Mono Class Library: System.Exception Overview | MembersSystem.Exception.GetBaseException Method |
Returns the Exception that is the root cause of one or more subsequent Exceptions. [Edit]
|
Returns the first Exception thrown in a chain of Exceptions. If the Exception.InnerException property of the current Exception is null , returns the current Exception. [Edit]
Note: 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 Exception.InnerException 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 baseexception and its Exception.InnerException property always contains a null reference.Operation
For all Exceptions in a chain of Exceptions, the Exception.GetBaseException method is required to return the same object (the base exception ).Note to Inheritors
The Exception.GetBaseException method is overridden in classes that require control over the exception content or format.Usage
Use the Exception.GetBaseException 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. [Edit]
The following example shows an implementation of the Exception.GetBaseException method.
C# Example public virtual Exception GetBaseException() { Exception inner = InnerException; Exception back = this; while (inner != null) { back = inner; inner = inner.InnerException; } return back; }
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0