Win32Exception クラス

定義

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
継承
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();
    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 エラー コード」を参照してください。

コンストラクター

名前 説明
Win32Exception()

最後に発生した Win32 エラーを使用して、 Win32Exception クラスの新しいインスタンスを初期化します。

Win32Exception(Int32, String)

指定したエラーと指定した詳細な説明を使用して、 Win32Exception クラスの新しいインスタンスを初期化します。

Win32Exception(Int32)

指定したエラーを使用して、 Win32Exception クラスの新しいインスタンスを初期化します。

Win32Exception(SerializationInfo, StreamingContext)

指定したコンテキストとシリアル化情報を使用して、 Win32Exception クラスの新しいインスタンスを初期化します。

Win32Exception(String, Exception)

指定した詳細な説明と指定した例外を使用して、 Win32Exception クラスの新しいインスタンスを初期化します。

Win32Exception(String)

指定した詳細な説明を使用して、 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()

派生クラスでオーバーライドされた場合、1 つ以上の後続の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

このSerializationInfoが発生したファイル名と行番号を使用して、Win32Exception オブジェクトを設定します。

GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

NativeErrorCodeHResult、またはその両方を含む文字列を返します。

ToString()

現在の例外の文字列形式を作成して返します。

(継承元 Exception)
ToString()

エラーの HRESULT を含む文字列を返します。

(継承元 ExternalException)

イベント

名前 説明
SerializeObjectState

例外に関するシリアル化されたデータを含む例外状態オブジェクトを作成するために例外がシリアル化されるときに発生します。

(継承元 Exception)

適用対象