ErrorEventArgs(Exception) Constructeur

Définition

Initialise une nouvelle instance de la classe ErrorEventArgs.

public:
 ErrorEventArgs(Exception ^ exception);
public ErrorEventArgs(Exception exception);
new System.IO.ErrorEventArgs : Exception -> System.IO.ErrorEventArgs
Public Sub New (exception As Exception)

Paramètres

exception
Exception

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 à