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.
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.
PROPERTY | DESCRIPTION |
---|---|
HelpLink | Represents the link to the help file associated with the exception (both get and set) |
InnerException | Returns the Exception instance that caused the current exception (get only) |
Message | Returns the error message that describes the current exception (read only) |
Source | Represents the name of the application or object that caused the error (both get and set) |
StackTrace | Returns a string of the frames on the call stack at the time the exception occurred (read only) |
TargetSite | Returns the method that throws the exception (read only) |
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.