System.ArithmeticException Class
Represents an error caused by an arithmetic operation.

See Also: ArithmeticException Members

Syntax

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

Remarks

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:

  • ckfinite
  • div

Thread Safety

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

Example

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

C# Example

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

Requirements

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