Win32Exception 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會拋出 Win32 錯誤代碼的例外。
public ref class Win32Exception : Exception
public ref class Win32Exception : System::Runtime::InteropServices::ExternalException
public class Win32Exception : Exception
[System.Serializable]
public class Win32Exception : System.Runtime.InteropServices.ExternalException
public class Win32Exception : System.Runtime.InteropServices.ExternalException
type Win32Exception = class
inherit Exception
[<System.Serializable>]
type Win32Exception = class
inherit ExternalException
interface ISerializable
type Win32Exception = class
inherit ExternalException
interface ISerializable
Public Class Win32Exception
Inherits Exception
Public Class Win32Exception
Inherits ExternalException
- 繼承
- 繼承
- 衍生
- 屬性
- 實作
範例
以下程式碼範例說明如何捕捉 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();
myProc.StartInfo.FileName = @"c:\nonexist.exe"; // Attempt to start a non-existent executable
_ = myProc.Start();
}
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 錯誤代碼。
建構函式
| 名稱 | Description |
|---|---|
| Win32Exception() |
初始化一個新的類別實例 Win32Exception ,並帶有最後一次 Win32 錯誤。 |
| Win32Exception(Int32, String) |
初始化一個新實例, Win32Exception 並以指定的錯誤與詳細描述。 |
| Win32Exception(Int32) |
初始化一個新的類別實例 Win32Exception ,並以指定的錯誤值。 |
| Win32Exception(SerializationInfo, StreamingContext) |
初始化一個新的類別實例 Win32Exception ,並依指定的上下文與序列化資訊。 |
| Win32Exception(String, Exception) |
初始化一個帶有指定詳細描述與例外的新類別實例 Win32Exception 。 |
| Win32Exception(String) |
初始化一個包含特定詳細描述的 Win32Exception 類別新實例。 |
屬性
| 名稱 | Description |
|---|---|
| Data |
取得索引鍵/值組的集合,提供例外狀況的其他使用者定義資訊。 (繼承來源 Exception) |
| ErrorCode |
明白 |
| HelpLink |
取得或設定與這個例外狀況相關聯的說明檔連結。 (繼承來源 Exception) |
| HResult |
取得或設定 HRESULT,這是指派給特定例外狀況的編碼數值。 (繼承來源 Exception) |
| InnerException |
會取得 Exception 造成目前例外的實例。 (繼承來源 Exception) |
| Message |
取得描述目前例外狀況的訊息。 (繼承來源 Exception) |
| NativeErrorCode |
會收到與此例外相關的 Win32 錯誤代碼。 |
| Source |
取得或設定造成錯誤之應用程式或物件的名稱。 (繼承來源 Exception) |
| StackTrace |
取得呼叫堆疊上即時框架的字串表示。 (繼承來源 Exception) |
| TargetSite |
取得擲回目前例外狀況的方法。 (繼承來源 Exception) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetBaseException() |
當在派生類別中被覆寫時,回傳 Exception 是一個或多個後續例外的根因。 (繼承來源 Exception) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
會以檔案名稱和發生此事SerializationInfo的行號來設定物件。Win32Exception |
| GetType() |
取得目前實例的運行時間類型。 (繼承來源 Exception) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
回傳包含 NativeErrorCode、 或 HResult,或兩者皆有的字串。 |
| ToString() |
建立並傳回目前例外狀況的字串表示。 (繼承來源 Exception) |
| ToString() |
回傳包含錯誤 HRESULT 的字串。 (繼承來源 ExternalException) |
事件
| 名稱 | Description |
|---|---|
| SerializeObjectState |
發生於例外狀況串行化以建立例外狀況狀態物件,其中包含例外狀況的串行化數據。 (繼承來源 Exception) |