Mono Class Library: System Namespace

System.OverflowException Class

Represents the error that occurs when the result of an arithmetic operation is too large to be represented by the destination type. [Edit]

See Also: OverflowException Members

System.Object
     System.Exception
          System.SystemException
               System.ArithmeticException
                    System.OverflowException

[System.Runtime.InteropServices.ComVisible(true)]
public class OverflowException : ArithmeticException

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

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.

Note:

The following CIL instructions throw OverflowException :

  • add.ovf.<signed>
  • conv.ovf.<to type>
  • conv.ovf.<to type>.un
  • mul.ovf.<type>
  • sub.ovf.<type>
  • newarr
[Edit]

Example

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()
 

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0