Name

Exception

Synopsis

This is the base class for all .NET exceptions. .NET Framework exceptions are generally derived from SystemException, and user-defined exceptions are generally derived from ApplicationException.

In some cases, one exception may throw another; this is often the case when using layered architectures. For example, a persistence layer may throw a persistence-related exception (DatabaseNotFoundException), whose semantics are undefined at a higher level (such as the UI layer). In this case, a middle layer may throw a new exception-derived type (such as PersistenceException), but doesn’t wish to lose the original source of the exception—instead, it wraps the original exception by setting it to be the InnerException. In this way, a layer can communicate a lower-level exception to higher layers without losing information or violating encapsulation.

The StackTrace property is a string containing the stacktrace. This permits determination of the call sequence leading up to the line that threw the exception. HelpLink contains a link to a help file with information about the exception. Message contains a text message that describes the exception.

public class Exception : System.Runtime.Serialization.ISerializable {
// Public Constructors
   public Exception( );
   public Exception(string message);
   public Exception(string message, Exception innerException);
// Protected Constructors
   protected Exception(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext ...

Get C# in a Nutshell, Second Edition 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.