-checked (C# Compiler Options)
The -checked option specifies whether an integer arithmetic statement that results in a value that is outside the range of the data type, and that is not in the scope of a checked or unchecked keyword, causes a run-time exception.
-checked[+ | -]
An integer arithmetic statement that is in the scope of a
unchecked keyword is not subject to the effect of the -checked option.
If an integer arithmetic statement that is not in the scope of a
unchecked keyword results in a value outside the range of the data type, and -checked+ (or -checked) is used in the compilation, that statement causes an exception at run time. If -checked- is used in the compilation, that statement does not cause an exception at run time.
The default value for this option is -checked-; overflow checking is disabled.
Sometimes, automated tools that are used to build large applications set -checked to +. One scenario for using -checked- is to override the tool's global default by specifying -checked-.
To set this compiler option in the Visual Studio development environment
Open the project's Properties page. For more information, see Build Page, Project Designer (C#).
Click the Build property page.
Click the Advanced button.
Modify the Check for arithmetic overflow/underflow property.
To access this compiler option programmatically, see CheckForOverflowUnderflow.
The following command compiles
t2.cs. The use of
-checked in the command specifies that any integer arithmetic statement in the file that is not in the scope of a
unchecked keyword, and that results in a value that is outside the range of the data type, causes an exception at run time.
csc t2.cs -checked
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.