public class DivideByZeroException : ArithmeticException
Object
Exception
SystemException
ArithmeticException
DivideByZeroException
mscorlib
BCL
Represents the error that is caused by an attempt to divide a number by zero.
[Note: The following CIL instructions throw DivideByZeroException:
]
- div
- div.un
- rem
- rem.un
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()
System Namespace
DivideByZeroException Constructors
DivideByZeroException() Constructor
DivideByZeroException(System.String) Constructor
DivideByZeroException(System.String, System.Exception) Constructor
public DivideByZeroException();
Constructs and initializes a new instance of the DivideByZeroException class.
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
.
System.DivideByZeroException Class, System Namespace
public DivideByZeroException(string message);
Constructs and initializes a new instance of the DivideByZeroException class.
- 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.
This constructor initializes the System.DivideByZeroException.Message property of the new instance using message . If message isnull
, 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 tonull
.
System.DivideByZeroException Class, System Namespace
public DivideByZeroException(string message, Exception innerException);
Constructs and initializes a new instance of the DivideByZeroException class.
- 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 .
This constructor initializes the System.DivideByZeroException.Message property of the new instance using message, and the System.DivideByZeroException.InnerException property using innerException. If message isnull
, 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.]
System.DivideByZeroException Class, System Namespace