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 property returns the same value as was passed into the Exception(String, Exception) constructor, or a null reference (Nothing in Visual Basic) if the inner exception value was not supplied to the constructor. This property is read-only.
When an exception X is thrown as a direct result of a previous exception Y, the property of X should contain a reference to Y.
Use the property 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.
The property, which holds a reference to the inner exception, is set upon initialization of the exception object.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8