Win32Exception 類別

定義

擲回 Win32 錯誤碼的例外狀況。

public ref class Win32Exception : Exception
public ref class Win32Exception : System::Runtime::InteropServices::ExternalException
public class Win32Exception : Exception
public class Win32Exception : System.Runtime.InteropServices.ExternalException
[System.Serializable]
public class Win32Exception : System.Runtime.InteropServices.ExternalException
type Win32Exception = class
    inherit Exception
type Win32Exception = class
    inherit ExternalException
    interface ISerializable
[<System.Serializable>]
type Win32Exception = class
    inherit ExternalException
    interface ISerializable
Public Class Win32Exception
Inherits Exception
Public Class Win32Exception
Inherits ExternalException
繼承
Win32Exception
繼承
衍生
屬性
實作

範例

下列程式碼範例示範如何攔截 Win32 例外狀況並解譯其內容。 此範例會嘗試啟動不存在的可執行檔,這會導致 Win32 例外狀況。 攔截例外狀況時,此範例會擷取例外狀況的個別錯誤訊息、程式碼和來源。

try
{
   System::Diagnostics::Process^ myProc = gcnew System::Diagnostics::Process;
   //Attempting to start a non-existing executable
   myProc->StartInfo->FileName = "c:\nonexist.exe";
   //Start the application and assign it to the process component.
   myProc->Start();
}
catch ( Win32Exception^ w ) 
{
   Console::WriteLine( w->Message );
   Console::WriteLine( w->ErrorCode );
   Console::WriteLine( w->NativeErrorCode );
   Console::WriteLine( w->StackTrace );
   Console::WriteLine( w->Source );
   Exception^ e = w->GetBaseException();
   Console::WriteLine( e->Message );
}
try {
System.Diagnostics.Process myProc = new System.Diagnostics.Process();
myProc.StartInfo.FileName = "c:\nonexist.exe";  //Attempting to start a non-existing executable
myProc.Start();    //Start the application and assign it to the process component.    
}
catch(Win32Exception w) {
Console.WriteLine(w.Message);
Console.WriteLine(w.ErrorCode.ToString());
Console.WriteLine(w.NativeErrorCode.ToString());
Console.WriteLine(w.StackTrace);
Console.WriteLine(w.Source);
Exception e=w.GetBaseException();
Console.WriteLine(e.Message);
}
Try
    Dim myProc As New System.Diagnostics.Process()
    myProc.StartInfo.FileName = "c:\nonexist.exe"  'Attempting to start a non-existing executable
    myProc.Start()    'Start the application and assign it to the process component.    

Catch w As System.ComponentModel.Win32Exception
    Console.WriteLine(w.Message)
    Console.WriteLine(w.ErrorCode.ToString())
    Console.WriteLine(w.NativeErrorCode.ToString())
    Console.WriteLine(w.StackTrace)
    Console.WriteLine(w.Source)
    Dim e As New Exception()
    e = w.GetBaseException()
    Console.WriteLine(e.Message)
End Try

備註

Win32 錯誤碼在顯示時,會從數字表示轉譯為系統訊息。 使用 NativeErrorCode 來存取與此例外狀況相關聯之錯誤碼的數值表示。 如需錯誤碼的詳細資訊,請參閱 Win32 錯誤碼

建構函式

Win32Exception()

使用最後發生的 Win32 錯誤,初始化 Win32Exception 類別的新執行個體。

Win32Exception(Int32)

使用指定的錯誤來初始化 Win32Exception 類別的新執行個體。

Win32Exception(Int32, String)

使用指定的錯誤和指定的詳細描述來初始化 Win32Exception 類別的新執行個體。

Win32Exception(SerializationInfo, StreamingContext)

使用指定的內容和序列化 (Serialization) 資訊,初始化 Win32Exception 類別的新執行個體。

Win32Exception(String)

使用指定的詳細描述來初始化 Win32Exception 類別的新執行個體。

Win32Exception(String, Exception)

使用指定的詳細描述和指定的例外狀況,初始化 Win32Exception 類別的新執行個體。

屬性

Data

取得鍵值組的集合,這些鍵值組會提供關於例外狀況的其他使用者定義資訊。

(繼承來源 Exception)
ErrorCode

取得錯誤的 HRESULT

(繼承來源 ExternalException)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。

(繼承來源 Exception)
Message

取得描述目前例外狀況的訊息。

(繼承來源 Exception)
NativeErrorCode

取得與這個例外狀況關聯的 Win32 錯誤碼。

Source

取得或設定造成錯誤的應用程式或物件的名稱。

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 Exception

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

以發生這個 SerializationInfo 的檔案名稱和行號,設定 Win32Exception 物件。

GetObjectData(SerializationInfo, StreamingContext)

在衍生類別中覆寫時,使用例外狀況的資訊設定 SerializationInfo

(繼承來源 Exception)
GetType()

取得目前執行個體的執行階段類型。

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回包含 NativeErrorCode,或 HResult,或同時包含兩者的字串。

ToString()

建立並傳回目前例外狀況的字串表示。

(繼承來源 Exception)
ToString()

傳回字串,其中包含錯誤的 HRESULT。

(繼承來源 ExternalException)

事件

SerializeObjectState
已淘汰.

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。

(繼承來源 Exception)

適用於