Home > Articles > Programming > Windows Programming

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


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.




A non-fatal application error occurred.


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


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


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


Error in an arithmetic, casting, or conversion operation.


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


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


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


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


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


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


Invalid casting or explicit conversion.


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


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


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


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


An attempt to dereference a null object reference.


An operation is performed on a disposed object.


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


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


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


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


A wrapper around the exception thrown by the type initializer.


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

  • + Share This
  • 🔖 Save To Your Account