System.OverflowException Class

public class OverflowException : ArithmeticException

Base Types

Object
  Exception
    SystemException
      ArithmeticException
        OverflowException

Assembly

mscorlib

Library

BCL

Summary

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

Description

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 :

]

Example

The following example demonstrates an error that causes a OverflowException exception.

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

Error caught: System.OverflowException: Arithmetic operation resulted in an overflow.
   at OverflowExample.Main()
 

See Also

System Namespace

Members

OverflowException Constructors

OverflowException() Constructor
OverflowException(System.String) Constructor
OverflowException(System.String, System.Exception) Constructor


OverflowException() Constructor

public OverflowException();

Summary

Constructs and initializes a new instance of the OverflowException class.

Description

This constructor initializes the System.OverflowException.Message property of the new instance to a system-supplied message that describes the error. This message takes into account the current system culture.

The System.OverflowException.InnerException property is initialized to null .

See Also

System.OverflowException Class, System Namespace

OverflowException(System.String) Constructor

public OverflowException(string message);

Summary

Constructs and initializes a new instance of the OverflowException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

Description

This constructor initializes the System.OverflowException.Message property of the new instance using message. If message is null , the System.OverflowException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments. The System.OverflowException.InnerException property is initialized to null .

See Also

System.OverflowException Class, System Namespace

OverflowException(System.String, System.Exception) Constructor

public OverflowException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the OverflowException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
innerException
An instance of Exception that is the cause of the current Exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException .

Description

This constructor initializes the System.OverflowException.Message property of the new instance using message, and the System.OverflowException.InnerException property using innerException . If message is null , the System.OverflowException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

[Note: For information on inner exceptions, see System.Exception.InnerException .]

See Also

System.OverflowException Class, System Namespace