System.ArithmeticException Class

public class ArithmeticException : SystemException

Base Types

Object
  Exception
    SystemException
      ArithmeticException

Assembly

mscorlib

Library

BCL

Summary

Represents an error caused by an arithmetic operation.

Description

[Note: The Base Class Library includes two types derived from ArithmeticException:

When appropriate, use these types instead of ArithmeticException.

]

[Note: The following CIL instructions throw ArithmeticException:

]

Example

The following example demonstrates an error that causes the system to throw a ArithmeticException error.

using System;
class testNan {
 public static void Main() {
   double myNan = Double.NaN;
   try {
     Math.Sign(myNan);
   }
   catch (ArithmeticException e) {
     Console.WriteLine("Error: {0}",e);
   }
 }
}
   
The output is

Error: System.ArithmeticException: Function does not accept floating point Not-a-Number values.

at System.Math.Sign(Double value)

at testNan.Main()

See Also

System Namespace

Members

ArithmeticException Constructors

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


ArithmeticException() Constructor

public ArithmeticException();

Summary

Constructs and initializes a new instance of the ArithmeticException class.

Description

This constructor initializes the System.ArithmeticException.Message property of the new instance to a system-supplied message that describes the error, such as "The arithmetic operation is not allowed." This message takes into account the current system culture.

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

See Also

System.ArithmeticException Class, System Namespace

ArithmeticException(System.String) Constructor

public ArithmeticException(string message);

Summary

Constructs and initializes a new instance of the ArithmeticException 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.ArithmeticException.Message property of the new instance using message. If message is null , the System.ArithmeticException.Message property is initialized to a system-supplied message. The System.ArithmeticException.InnerException property is initialized to null .

See Also

System.ArithmeticException Class, System Namespace

ArithmeticException(System.String, System.Exception) Constructor

public ArithmeticException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the ArithmeticException 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.ArithmeticException.Message property of the new instance using message, and the System.Exception.InnerException property using innerException. If message is null , the System.ArithmeticException.Message property is initialized to a system-supplied message.

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

See Also

System.ArithmeticException Class, System Namespace