asp.net.ph

Exception Class

System Namespace


Defines the base class for all exceptions.

Exception Class Members

Collapse   Constructors

Visibility Constructor Parameters
public Exception ( )
public Exception ( String message )
public Exception ( String message , Exception innerException )

Collapse   Properties

Visibility Name Value Type Accessibility
public Data IDictionary [ Get ]
public HelpLink String [ Get , Set ]
public HResult Int32 [ Get ]
public InnerException Exception [ Get ]
public Message String [ Get ]
public Source String [ Get , Set ]
public StackTrace String [ Get ]
public TargetSite MethodBase [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public GetBaseException ( ) Exception
public GetObjectData ( SerializationInfo info , StreamingContext context ) Void
public GetType ( ) Type
public ToString ( ) String

Remarks

This class is the base class for all exceptions.

Exceptions are responses to abnormal or exceptional conditions that arise while a program is executing. When an error occurs, either the system or the currently executing application reports it by throwing an exception containing information about the error. Once thrown, an exception is handled by the application or by the default exception handler.

The common language runtime provides an exception handling model that is based on the representation of exceptions as objects, and the separation of program code and exception handling code into try and catch blocks, respectively. There can be one or more catch blocks, each designed to handle a particular type of exception, or one block designed to catch a more specific exception than another block.

When an exception occurs in the try block, control is passed to a catch block that handles that exception. If the execution path has several methods calling each other in a sequence, the exception is passed up the call stack until the runtime finds a handler for it. If no handler is found, the default handler is called by the runtime to display the exception name, the error message, and a stack trace identifying the method where the exception is thrown. For more information, see Handling and Throwing Exceptions.

There are two categories of exceptions under the base class Exception:

Exception includes a number of properties that help identify the code location, the type, the help file, and the reason for the exception: StackTrace, InnerException, Message, HelpLink, HResult, Source, and TargetSite.

The StackTrace property carries a stack trace that can be used to determine where the error occurs in the code. The stack trace lists all the called methods, and the line numbers in the source file where the calls are made.

When handling exceptions, it is useful to capture a series of related exceptions, with the outer exception being thrown in response to an inner exception. The code that handles the second exception can use the information from the earlier exception to handle the error more appropriately.

A reference to the inner exception that causes the outer exception is available from the InnerException property of the outer exception. This exception-linking mechanism preserves the error information carried by earlier exceptions, including the original exception, while allowing you to create more meaningful outer exceptions.

When an exception occurs, the runtime makes available a text message to inform the user of the nature of the error and to suggest action to resolve the problem. This text message is held in the Message property of the exception object. During the creation of the exception object, you can pass a text string to the constructor to describe the details of that particular exception. If there is no error message argument supplied to the constructor, the default error message is used.

The error message string passed to the constructor during the creation of the exception object should be localized, and can be supplied from a resource file using the ResourceManager. For more information on localized resources, see the System.Resources namespace overview and Deploying Resource Files.

To provide the user with extensive information concerning why the exception occurred, the HelpLink property can hold a URL ( or URN ) to a help file.

Exception uses the HRESULT COR_E_EXCEPTION, which has the value 0x80131500.

For a list of initial property values for an instance of Exception, see the Exception constructors.

Skip Navigation Links



Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph