Gets the Exception instance that caused the current exception.
Assembly: mscorlib (in mscorlib.dll)
abstract InnerException : Exception with get override InnerException : Exception with get
Property ValueType: System.Exception
An object that describes the error that caused the current exception. The Exception(String, Exception) constructor, or null if the inner exception value was not supplied to the constructor. This property is read-only.property returns the same value as was passed into the
When an exception X is thrown as a direct result of a previous exception Y, theproperty of X should contain a reference to Y.
Use theproperty to obtain the set of exceptions that led to the current exception.
You can create a new exception that catches an earlier exception. The code that handles the second exception can make use of the additional information from the earlier exception to handle the error more appropriately.
Suppose that there is a function that reads a file and formats the data from that file. In this example, as the code tries to read the file, an IOException is thrown. The function catches the IOException and throws a FileNotFoundException. The IOException could be saved in the property of the FileNotFoundException, enabling the code that catches the FileNotFoundException to examine the cause of the initial error.
Theproperty, which holds a reference to the inner exception, is set upon initialization of the exception object.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1