O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

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

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 a loss of 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 method Exception();  
   public method Exception(string message);  
   public method Exception(string message, 
        Exception innerException);  
// Protected Constructors
   protected method Exception( System.Runtime.Serialization.SerializationInfo ...

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