System.DivideByZeroException Class

public class DivideByZeroException : ArithmeticException

Base Types

Object
  Exception
    SystemException
      ArithmeticException
        DivideByZeroException

Assembly

mscorlib

Library

BCL

Summary

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

Description

[Note: The following IL instructions throw DivideByZeroException:

]

Example

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

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

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

See Also

System Namespace

Members

DivideByZeroException Constructors

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


DivideByZeroException() Constructor

public DivideByZeroException();

Summary

Constructs and initializes a new instance of the DivideByZeroException class.

Description

This constructor initializes the System.DivideByZeroException.Message property of the new instance to a system-supplied message that describes the error, such as "Attempted to divide by zero." This message takes into account the current system culture.

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

See Also

System.DivideByZeroException Class, System Namespace

DivideByZeroException(System.String) Constructor

public DivideByZeroException(string message);

Summary

Constructs and initializes a new instance of the DivideByZeroException 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.DivideByZeroException.Message property of the new instance using message . If message is null , the System.DivideByZeroException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments. The System.DivideByZeroException.InnerException property is initialized to null .

See Also

System.DivideByZeroException Class, System Namespace

DivideByZeroException(System.String, System.Exception) Constructor

public DivideByZeroException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the DivideByZeroException 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.DivideByZeroException.Message property of the new instance using message, and the System.DivideByZeroException.InnerException property using innerException. If message is null , the System.DivideByZeroException.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.]

See Also

System.DivideByZeroException Class, System Namespace