Partilhar via


ErrorEventArgs(Exception) Construtor

Definição

Inicializa uma nova instância da classe ErrorEventArgs.

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

Parâmetros

exception
Exception

Um Exception que representa o erro ocorrido.

Exemplos

O exemplo a seguir cria uma nova instância de ErrorEventArgs e a inicializa com um Exception. Em seguida, o exemplo chama GetException para recuperar o Exception e exibir a mensagem de erro. Não há nenhum formulário associado a este código.

int main()
{
   
   //Creates an exception with an error message.
   Exception^ myException = gcnew Exception( "This is an exception test" );
   
   //Creates an ErrorEventArgs with the exception.
   ErrorEventArgs^ myErrorEventArgs = gcnew ErrorEventArgs( myException );
   
   //Extracts the exception from the ErrorEventArgs and display it.
   Exception^ myReturnedException = myErrorEventArgs->GetException();
   MessageBox::Show( String::Concat( "The returned exception is: ", myReturnedException->Message ) );
}

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

Aplica-se a