Mono Class Library: System Namespace

System.DivideByZeroException Class

Represents the error that is caused by an attempt to divide a number by zero. [Edit]

See Also: DivideByZeroException Members

System.Object
     System.Exception
          System.SystemException
               System.ArithmeticException
                    System.DivideByZeroException

[System.Runtime.InteropServices.ComVisible(true)]
public class DivideByZeroException : 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

Note:

The following CIL instructions throw DivideByZeroException:

  • div
  • div.un
  • rem
  • rem.un
[Edit]

Example

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

C# Example
using System;
public class DivideZeroTest {
 public static void Main() {
   int x = 0;
   try { 
     int y = 100/x;
   }
   catch (DivideByZeroException e) {
     Console.WriteLine("Error: {0}",e);
   }
 }
}
   

The output is

Example
Error: System.DivideByZeroException: Attempted to divide by zero.
   at DivideZeroTest.Main()
 

Requirements

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