Understanding the Exception Classes

By now you probably have an idea of how to implement exception handling in your code. The following sections give a quick overview of the exception-related classes provided by the .NET Framework Library.

Using the Exception Class: Mother of All Exceptions

The Exception class represents errors that occur during application execution. This class is the base class for all exception classes. In the previous samples, you already saw how to create an object of the Exception class. Table 9-1 describes the Exception class properties.

Table 9-1: Exception Class Properties




Represents the link to the help file associated with the exception (both get and set)


Returns the Exception instance that caused the current exception (get only)


Returns the error message that describes the current exception (read only)


Represents the name of the application or object that caused the error (both get and set)


Returns a string of the frames on the call stack at the time the exception occurred (read only)


Returns the method that throws the exception (read only)

Understanding Other Exception Classes

The .NET Framework Class Library defines many exception classes, and each of them is designed to handle a specific kind of exception. For example, an IOException error is thrown when an I/O error occurs.

The SystemException class is the base class for system (runtime) errors. Some of the classes derived from SystemException are StackOverflowException, ArithmeticException, ArrayTypeMismatchException, FormatException, IOException, OutOfMemory-Exception, RankException, and TypeLoadException.

The .NET Framework Library defines hundreds of exception classes—some of which are specific to a particular operation. For example, an OutOfMemory exception is thrown when there's not enough memory to continue the execution of a program. Discussing all of the exception classes is beyond the scope of this chapter.

Applied ADO. NET(c) Building Data-Driven Solutions
Applied ADO.NET: Building Data-Driven Solutions
ISBN: 1590590732
EAN: 2147483647
Year: 2006
Pages: 214

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net