System.Exception Members

This page lists the key members of the System.Exception class, the base class for all exceptions in the .NET Framework. Understanding these members is crucial for effective error handling and debugging.

Commonly Used Members

Message Property

Gets a message that describes the current exception.

This property provides a human-readable description of the error that occurred.

InnerException Property

Gets the exception that is the cause of the current exception.

Used to chain exceptions, allowing you to preserve the original exception while throwing a new one.

StackTrace Property

Gets a string representation of the frames in the call stack.

Provides detailed information about the sequence of method calls that led to the exception.

GetType() Method

Returns the runtime type of the current instance.

Helps in identifying the specific type of exception that was thrown.

ToString() Method

Overrides to return a string that represents the current exception.

Includes the exception type, message, and stack trace for comprehensive error reporting.

Data Property

Gets a dictionary containing information about the exception that is specific to the application.

Allows for storing custom key-value pairs related to the exception.

Constructors

The System.Exception class provides several constructors to create exception objects. The most common ones are:

Exception()

Initializes a new instance of the Exception class.

Exception(string message)

Initializes a new instance of the Exception class with a specified error message.

Exception(string message, Exception innerException)

Initializes a new instance of the Exception class with a specified error message and a reference to the inner exception that is the cause of this exception.

See Also