GetException Method
Collapse the table of content
Expand the table of content

ErrorEventArgs.GetException Method ()


Gets the Exception that represents the error that occurred.

Namespace:   System.IO
Assembly:  System (in System.dll)

public virtual Exception GetException()

Return Value

Type: System.Exception

An Exception that represents the error that occurred.

The following example creates a new instance of ErrorEventArgs and initializes it with an Exception. Then the example calls GetException to retrieve the Exception and display the error message. There is no form associated with this code.

public static void Main(string[] args) {
   //Creates an exception with an error message.
   Exception myException= new Exception("This is an exception test");

   //Creates an ErrorEventArgs with the exception.
   ErrorEventArgs myErrorEventArgs = new ErrorEventArgs(myException);

   //Extracts the exception from the ErrorEventArgs and display it.
   Exception myReturnedException = myErrorEventArgs.GetException();
   MessageBox.Show("The returned exception is: " + myReturnedException.Message);

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft