ErrorEventArgs.GetException Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Exception Hämtar det som representerar felet som inträffade.
public:
virtual Exception ^ GetException();
public virtual Exception GetException();
abstract member GetException : unit -> Exception
override this.GetException : unit -> Exception
Public Overridable Function GetException () As Exception
Returer
Ett Exception som representerar felet som inträffade.
Exempel
I följande exempel skapas en ny instans av ErrorEventArgs och initieras med en Exception. Sedan anropar GetException exemplet för att hämta Exception och visa felmeddelandet. Det finns inget formulär som är associerat med den här koden.
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);
}
Public Shared Sub Main()
'Creates an exception with an error message.
Dim myException As New Exception("This is an exception test")
'Creates an ErrorEventArgs with the exception.
Dim myErrorEventArgs As New ErrorEventArgs(myException)
'Extracts the exception from the ErrorEventArgs and display it.
Dim myReturnedException As Exception = myErrorEventArgs.GetException()
MessageBox.Show("The returned exception is: " _
+ myReturnedException.Message)
End Sub