public class OverflowException : ArithmeticException
Object
Exception
SystemException
ArithmeticException
OverflowException
mscorlib
BCL
Represents the error that occurs when the result of an arithmetic operation is too large to be represented by the destination type.
In languages that detect overflow, this is the exception that gets thrown. For example, in C#, thechecked
keyword is used to detect overflow conditions. A OverflowException exception occurs only in achecked
context.[Note: The following IL instructions throw OverflowException :
]
- add.ovf.<signed>
- conv.ovf.<to type>
- conv.ovf.<to type>.un
- mul.ovf.<type>
- sub.ovf.<type>
- newarr
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()
System Namespace
OverflowException Constructors
OverflowException() Constructor
OverflowException(System.String) Constructor
OverflowException(System.String, System.Exception) Constructor
public OverflowException();
Constructs and initializes a new instance of the OverflowException class.
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
.
System.OverflowException Class, System Namespace
public OverflowException(string message);
Constructs and initializes a new instance of the OverflowException class.
- 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.
This constructor initializes the System.OverflowException.Message property of the new instance using message. If message isnull
, 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 tonull
.
System.OverflowException Class, System Namespace
public OverflowException(string message, Exception innerException);
Constructs and initializes a new instance of the OverflowException class.
- 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 .
This constructor initializes the System.OverflowException.Message property of the new instance using message, and the System.OverflowException.InnerException property using innerException . If message isnull
, 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 .]
System.OverflowException Class, System Namespace