C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: An int is 4 bytes. More bytes would be needed to represent the desired number.
Info: If you use no checked context (or the unchecked context), the program proceeds like nothing is amiss.
And: It doesn't give you the number you probably expect. And this could cause problems you don't expect.
CheckedC# program that causes OverflowException
class Program
{
static void Main()
{
checked
{
int value = int.MaxValue + int.Parse("1");
}
}
}
Output
Unhandled Exception: System.OverflowException:
Arithmetic operation resulted in an overflow.
OverflowException: This could be trapped in a catch block if you needed to handle the problem at runtime.
Thus: Using a checked context can help alert you to logic problems in your program faster.