O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required