See Also: OverflowException Members
In languages that detect overflow, this is the exception that gets thrown. For example, in C#, the checked keyword is used to detect overflow conditions. A OverflowException exception occurs only in a checked context.
The following CIL instructions throw OverflowException :
The following example demonstrates an error that causes a OverflowException exception.
C# Example
using System;
public class OverflowExample {
public static void Main() {
int i = 400;
byte b = 0;
try {
checked { b = (byte)( i ); }
}
catch ( OverflowException e ) {
Console.WriteLine( "Error caught: {0}", e );
}
}
}
The output is
Example
Error caught: System.OverflowException: Arithmetic operation resulted in an overflow. at OverflowExample.Main()