ErrorEventArgs.GetException Méthode

Définition

Obtient la Exception valeur qui représente l’erreur qui s’est produite.

public:
 virtual Exception ^ GetException();
public virtual Exception GetException();
abstract member GetException : unit -> Exception
override this.GetException : unit -> Exception
Public Overridable Function GetException () As Exception

Retours

Qui Exception représente l’erreur qui s’est produite.

Exemples

L’exemple suivant crée une nouvelle instance de ErrorEventArgs et l’initialise avec un Exception. Ensuite, l’exemple appelle GetException pour récupérer le Exception message d’erreur et l’afficher. Aucun formulaire n’est associé à ce 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);
}
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

S’applique à