BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Runtime.InteropServices._Exception System.Runtime.Serialization.ISerializable System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None) System.Runtime.InteropServices.ComDefaultInterface(typeof(System.Runtime.InteropServices._Exception)) System.Runtime.InteropServices.ComVisible(true)

Represents errors that occur during application execution.

This class is the base class for all Exceptions.

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.

For a description of the exception handling model, see Partition I of the CLI Specification.

If an application handles exceptions that occur during the execution of a block of application code, the code is required to be placed within a statement. Application code within a statement is a . Application code that handles Exceptions thrown by a try block is placed within a statement, and is called a . Zero or more catch blocks are associated with a try block, and each catch block includes a type filter that determines the types of Exceptions it handles.

When an Exception occurs in a try block, the system searches the associated catch blocks in the order they appear in application code, until it locates a catch block that handles the Exception. A catch block handles an exception of type , if the type filter of the catch block specifies or any type that

derives from. The system stops searching after it finds the first catch block that handles the Exception. For this reason, in application code, a catch block that handles a type must be specified before a catch block that handles its base types, as demonstrated in the example that follows this section. A catch block that handles is specified last.

If the catch blocks associated with the current try block do not handle the Exception, and the current try block is nested within other try blocks in the current call, the catch blocks associated with the next enclosing try block are searched. If no catch block for the Exception is found, the system searches previous nesting levels in the current call. If no catch block for the Exception is found in the current call, the Exception is passed up the call stack, and the previous stack frame is searched for a catch block that handles the Exception. The search of the call stack continues until the Exception is handled or there are no more frames in the call stack. If the top of the call stack is reached without finding a catch block that handles the Exception, the default exception handler handles it and the application terminates.

types support the following features:

Human-readable text that describes the error. See property.
The state of the call stack when the Exception was thrown. See the property.
When there is a causal relationship between two or more Exceptions, this information is maintained via the property.

The Base Class Library provides two types that inherit directly from :

Most user-defined exceptions derive from . For more information, see and .

The following example demonstrates a catch block that is defined to handle errors. This catch block also catches errors because derives from , and there is no catch block explicitly defined for errors.

`using System; class ExceptionTestClass { public static void Main() { int x = 0; try { int y = 100/x; } catch (ArithmeticException e) { Console.WriteLine("ArithmeticException Handler: {0}", e.ToString()); } catch (Exception e) { Console.WriteLine("Generic Exception Handler: {0}", e.ToString()); } } }`

The output is

`ArithmeticException Handler: System.DivideByZeroException: Attempted to divide by zero. at ExceptionTestClass.Main()`
- Constructor

  Constructs and initializes a new instance of the class.

  This constructor initializes the property of the new instance to a system-supplied message that describes the error and takes into account the current system culture. The property is initialized to and the property is initialized to .

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  A that describes the error. The content of is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

  Constructs a new instance of the class.

  This constructor initializes the property of the new instance using . If is , the property is initialized to the system-supplied message provided by the constructor that takes no arguments. The property is initialized to and the property is initialized to .

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  To be added.
  To be added.
  To be added.
  To be added.
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  A that describes the error. The content of is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
  An instance of that is the cause of the current exception. If is non-null, then the current exception was raised in a catch block handling .

  Constructs a new instance of the class.

  This constructor initializes the property of the new instance using , and the property using . If is , the property is initialized to the system-supplied message provided by the constructor that takes no arguments.

  The property is initialized to .

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Collections.IDictionary To be added. To be added. To be added. 2.0.0.0 4.0.0.0
- Method
  System.Exception

  Returns the that is the root cause of one or more subsequent Exceptions.

  Returns the first Exception thrown in a chain of Exceptions. If the property of the current Exception is , returns the current Exception.

  A chain of Exceptions consists of a set of Exceptions such that each Exception in the chain was thrown as a direct result of the Exception referenced in its property. For a given chain, there can be exactly one Exception that is the root cause of all other Exceptions in the chain. This Exception is called the and its property always contains a null reference.

  For all Exceptions in a chain of Exceptions, the method is required to return the same object (the ).

  The method is overridden in classes that require control over the exception content or format.

  Use the method when you want to find the root cause of an Exception but do not need information about Exceptions that might have occurred between the current Exception and the first Exception.

  The following example shows an implementation of the method.

  `public virtual Exception GetBaseException() { Exception inner = InnerException; Exception back = this; while (inner != null) { back = inner; inner = inner.InnerException; } return back; }` 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Void `` `` To be added. To be added. To be added. To be added. 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Type To be added. To be added. To be added. 2.0.0.0 4.0.0.0
- Property
  System.String To be added. To be added. To be added. 1.0.5000.0 2.0.0.0 4.0.0.0
- Property
  System.Int32 To be added. To be added. To be added. 1.0.5000.0 2.0.0.0 4.0.0.0
- Property
  System.Exception

  Gets the instance that caused the current Exception.

  An instance of that describes the error that caused the current Exception.

  This property is read-only.

  When an Exception is thrown as a direct result of a previous exception , the property of should contain a reference to .

  The property returns the same value as was passed into the constructor, or if the inner exception value was not supplied to the constructor.

  Using the property, you can obtain the set of Exceptions that led to the current Exception. includes an example that demonstrates this procedure.

  The following example demonstrates throwing and catching an Exception that references an inner Exception.

  `using System; public class MyAppException:ApplicationException { public MyAppException (String message) : base (message) {} public MyAppException (String message, Exception inner) : base(message,inner) {} } public class ExceptExample { public void ThrowInner () { throw new MyAppException("ExceptExample inner exception"); } public void CatchInner() { try { this.ThrowInner(); } catch (Exception e) { throw new MyAppException("Error caused by trying ThrowInner.",e); } } } public class Test { public static void Main() { ExceptExample testInstance = new ExceptExample(); try { testInstance.CatchInner(); } catch(Exception e) { Console.WriteLine ("In Main catch block. Caught: {0}", e.Message); Console.WriteLine ("Inner Exception is {0}",e.InnerException); } } }`

  The output is

  `In Main catch block. Caught: Error caused by trying ThrowInner. Inner Exception is MyAppException: ExceptExample inner exception at ExceptExample.ThrowInner() at ExceptExample.CatchInner()` 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Property
  System.String

  Gets a containing a message that describes the current Exception.

  A that contains a detailed description of the error, or . This value is intended to be understood by humans.

  The text of should completely describe the error and should, when possible, explain how to correct it.

  The value of the property is included in the information returned by .

  This property is read-only.

  The property is set only when creating an Exception instance.

  If no message was supplied to the constructor for the current instance, the system supplies a default message that is formatted using the current system culture.

  The property is overridden in classes that require control over message content or format.

  Application code typically accesses this property when there is a need to display information about an exception that has been caught.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Event
  4.0.0.0
  System.EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs> To be added. To be added.
- Property
  System.String To be added. To be added. To be added. 1.0.5000.0 2.0.0.0 4.0.0.0
- Property
  System.String

  Gets a representation of the frames on the call stack at the time the current Exception was thrown.

  A that describes the contents of the call stack.

  might not report as many method calls as expected, due to code transformations, such as inlining, that occur during optimization.

  This property is read-only.

  The format of the information returned by this property is required to be identical to the format of the information returned by

  .

  The property is overridden in classes that require control over the stack trace content or format.

  Use the property to obtain a string representation of the contents of the call stack at the time the exception was thrown.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Reflection.MethodBase To be added. To be added. To be added. 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.String

  Creates and returns a representation of the current Exception.

  A representation of the current Exception.

  returns a representation of the current Exception that is intended to be understood by humans. Where the Exception contains culture-sensitive data, the string representation returned by is required to take into account the current system culture. Although there are no exact requirements for the format of the returned string, it should as much as possible reflect the value of the object as perceived by the user.

  This method overrides .

  The implementation obtains the fully qualified name of the current Exception, the message, the result of calling on the inner exception, and the result of calling . If any of these members is or equal to , its value is not included in the returned string.

  It is recommended, but not required, that be overridden to return information about members declared in the derived class. For example, the class overrides so that it returns the value of the property, if that value is not .

  Use the method to obtain a string representation of an Exception.

  The following example causes an Exception and displays the result of calling on that Exception.

  `using System; public class MyClass {} public class ArgExceptionExample { public static void Main() { MyClass my = new MyClass(); string s = "sometext"; try { int i = s.CompareTo(my); } catch (Exception e) { Console.WriteLine("Error: {0}",e.ToString()); } } }`

  The output is

  `Error: System.ArgumentException: Object must be of type String. at System.String.CompareTo(Object value) at ArgExceptionExample.Main()` 0 1.0.5000.0 2.0.0.0 4.0.0.0
0