次の方法で共有


ErrorEventArgs.GetException メソッド

発生したエラーを表す Exception を取得します。

Public Overridable Function GetException() As Exception
[C#]
public virtual Exception GetException();
[C++]
public: virtual Exception* GetException();
[JScript]
public function GetException() : Exception;

戻り値

発生したエラーを表す Exception

使用例

[Visual Basic, C#, C++] ErrorEventArgs の新しいインスタンスを作成し、そのインスタンスを Exception を使用して初期化する例を次に示します。次に GetException を呼び出して Exception を取得し、エラー メッセージを表示します。このコードに関連付けられたフォームはありません。

 
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

[C#] 

 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);
 }

[C++] 

int main() {
    //Creates an exception with an error message.
    Exception* myException= new Exception(S"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(String::Concat( S"The returned exception is: ", myReturnedException->Message ));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ErrorEventArgs クラス | ErrorEventArgs メンバ | System.IO 名前空間