ErrorEventArgs.GetException 方法

获取表示已发生的错误的 Exception

**命名空间:**System.IO
**程序集:**System(在 system.dll 中)

语法

声明
Public Overridable Function GetException As Exception
用法
Dim instance As ErrorEventArgs
Dim returnValue As Exception

returnValue = instance.GetException
public virtual Exception GetException ()
public:
virtual Exception^ GetException ()
public Exception GetException ()
public function GetException () : Exception

返回值

表示已发生的错误的 Exception

示例

下面的示例创建 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
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);
}
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.
    System.Exception myException = 
        new System.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.
    System.Exception myReturnedException = myErrorEventArgs.GetException();

    MessageBox.Show("The returned exception is: " 
        + myReturnedException.get_Message());
} //main

平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ErrorEventArgs 类
ErrorEventArgs 成员
System.IO 命名空间