System.Exception

.NET generates an exception object any time an unexpected condition is encountered. This enables a comprehensive, consistent approach to handling such conditions in any type of .NET module.

An exception object is an instance of a class that derives from a class named System.Exception. A variety of subclasses of System.Exception are available for different circumstances. These subclasses allow condition-specific information about the exception to be exposed.

The base Exception class has properties that contain useful information about typical exceptions, as shown in Tables 6.1 and 6.2.

Table 6.1 Exception Class Properties

Property Description
HelpLink A string indicating the link to help for this exception.
InnerException Returns the exception object reference to an inner (nested) exception.
Message A string that contains a description of the error, suitable for displaying to users.
Source The name of the object that generated the error.
StackTrace A read-only property. The stack trace is a list of the method calls at the point at which the exception was detected. That is, if MethodA called MethodB, and an exception occurred in MethodB, then the stack trace would contain both MethodA and MethodB.
TargetSite A read-only string property that holds the method that threw the exception.

Table 6.2 Exception Class Methods

Method Description
GetBaseException Returns the first exception in the chain
ToString Returns the error string, which might include as ...

Get Professional Visual Basic 2012 and .NET 4.5 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.