Understanding Exceptions

An exception occurs when a program encounters any unexpected problem, such as running out of memory or attempting to read from a file that no longer exists.

An exception generally results in abruptly terminating the program after displaying an error message. Ideally, your program should be capable of handling these exceptional situations and, if possible, gracefully recover from them. This is called exception handling . Proper use of exception handling can make your programs robust, as well as easy to develop and maintain.

The Common Language Runtime (CLR) views an exception as any object that encapsulates any information about the problems that occurred during program execution. The FCL provides two categories of exceptions:

  • ApplicationException ” Represents exceptions thrown by applications

  • SystemException ” Represents exceptions thrown by the CLR

Both of these exception classes derive from the base Exception class. Table 5.1 lists the important properties of all three of these classes.

Table 5.1. Important Properties of the Exception Class

Property

Description

HelpLink

Specifies the uniform resource locator (URL) of the help file associated with this exception.

InnerException

Specifies an exception associated with this exception. This property is helpful when a series of exceptions is involved. Each new exception can preserve the information about the previous exception by storing it in the InnerException property.

Message

Specifies textual information that indicates the reason for the error and provides possible resolutions .

Source

Specifies the name of the application causing the error.

StackTrace

Specifies where an error occurred. If the debugging information is available, the stack trace includes the name of the source file and the program line number.

TargetSite

Represents the method that throws the current exception.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

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