System.DivideByZeroException Class
Represents the error that is caused by an attempt to divide a number by zero.

See Also: DivideByZeroException Members

Syntax

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

Remarks

Note:

The following CIL instructions throw DivideByZeroException:

  • div
  • div.un
  • rem
  • rem.un

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 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, 4.0.0.0