Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Exceptions

In order to provide a common, rich, easily programmed and difficult to ignore way of signaling and handling errors, the .NET Framework supports structured exception handling. A caller places an exception handler on the stack at the point at which he wants to catch the error, using the try–catch syntax of his programming language. A called function wanting to signal an error creates an object of class System.Exception (or one derived from it) containing information about the error and throws it. The CLR searches up the call stack until it finds a handler for the type of exception that was thrown, at which time the stack is unwound and control transferred to the catch block, which contains the error-handling code.

The class System.Exception is the base class from which all exception objects derive. It contains such basic information as a message provided by the thrower and the stack trace at which the exception took place. The class System.SystemException derives from it, and all system-provided exceptions derive from that. This allows a programmer to differentiate between system-provided and programmer-built exceptions. The system-provided exceptions in Table 4 were felt to be common enough to occupy the base System namespace. Many more specialized exception classes live in subordinate namespaces.

Table 4.

Exception

Meaning

ApplicationException

A non-fatal application error occurred.

ArgumentException

One of the arguments provided to a method is not valid.

ArgumentNullException

A null reference is passed to a member that does not accept it as a valid argument.

ArgumentOutOfRangeException

The value of an argument is outside the allowable range of values as defined by the invoked member.

ArithmeticException

Error in an arithmetic, casting, or conversion operation.

ArrayTypeMismatchException

An attempt is made to store an element of the wrong type within an array.

DivideByZeroException

An attempt was made to divide an integral or decimal value by zero.

DuplicateWaitObjectException

An object appears more than once in an array of synchronization objects.

ExecutionEngineException

An internal error occurred in the execution engine of the common language runtime.

FormatException

The format of an argument does not meet the parameter specifications of the invoked method.

IndexOutOfRangeException

An attempt is made to access an element of an array with an index that is outside the bounds of the array.

InvalidCastException

Invalid casting or explicit conversion.

InvalidOperationException

A method call is invalid for the object's current state.

InvalidProgramException

A program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in a compiler.

NotFiniteNumberException

A floating-point value is positive infinity, negative infinity, or Not-a-Number (NaN).

NotSupportedException

An invoked method is not supported or not supported in the current mode of operation.

NullReferenceException

An attempt to dereference a null object reference.

ObjectDisposedException

An operation is performed on a disposed object.

OutOfMemoryException

There is not enough memory to continue the execution of a program.

OverflowException

An arithmetic, casting, or conversion operation in a checked context results in an overflow.

RankException

An array with the wrong number of dimensions is passed to a method.

StackOverflowException

The execution stack overflows by having too many pending method calls.

TypeInitializationException

A wrapper around the exception thrown by the type initializer.

UnauthorizedAccessException

The operating system denies access because of an I/O error or a specific type of security error.

  • + Share This
  • 🔖 Save To Your Account