AppDomain.UnhandledExceptionとは? わかりやすく解説

AppDomain.UnhandledException イベント

例外がキャッチされない場合に発生します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Event UnhandledException As
 UnhandledExceptionEventHandler
Dim instance As AppDomain
Dim handler As UnhandledExceptionEventHandler

AddHandler instance.UnhandledException, handler
public event UnhandledExceptionEventHandler UnhandledException
public:
virtual event UnhandledExceptionEventHandler^ UnhandledException {
    void add (UnhandledExceptionEventHandler^ value) sealed;
    void remove (UnhandledExceptionEventHandler^ value) sealed;
}
/** @event */
public final void add_UnhandledException (UnhandledExceptionEventHandler
 value)

/** @event */
public final void remove_UnhandledException
 (UnhandledExceptionEventHandler value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

このイベントは、キャッチされない例外の通知を提供します。このイベントにより、システムの既定のハンドラが例外をユーザーに報告し、アプリケーションを終了する前に、アプリケーションで例外に関する情報を記録できます。アプリケーションの状態に関する十分な情報を使用できる場合、後で回復に使用するためにプログラム データを保存するなど、その他のアクションが実行される場合もあります。未処理の例外により、プログラム データが回復できないほど破損する可能性があるため、警告が発信されます。

メモメモ

.NET Framework Version 1.0 および 1.1 では、このイベントが発生する前に、アプリケーションの終了とデバッグ オプションがユーザーに報告されます。

このイベントは、任意のアプリケーション ドメインで処理できます。既定のアプリケーション ドメインで処理される場合、このイベントは、すべてのアプリケーション ドメイン内のすべての未処理の例外に対して発生します。子ドメインで処理される場合、このイベントは、そのドメイン内の未処理の例外に対してだけ発生します。イベントが既定のドメインと子ドメインの両方で処理される場合、子ドメインの未処理の例外により、両方のドメインでこのイベントが発生します。

.NET Framework Version 1.0 および 1.1 では、メイン アプリケーション スレッド以外のスレッドで発生した未処理の例外は、ランタイムによってキャッチされたため、アプリケーションは終了しませんでした。したがって、アプリケーションを終了しなくても、UnhandledException イベントが発生しました。.NET Framework Version 2.0 では、このような応答のない障害が累積するとパフォーマンスの低下、データの破損、およびロックアップを招き、これらはすべてデバッグが難しいため、子スレッドの未処理の例外用のこのバックストップは削除されました。詳細については、「マネージ スレッドの例外」を参照してください。

このイベントのイベント ハンドラを登録するには、適切なアクセス許可が必要です。アクセス許可がないと、SecurityException がスローされます。

イベント処理の詳細については、「イベントの利用」を参照してください。

使用例使用例

UnhandledException イベントのサンプルを次に示します。

Sub Main()
   Dim currentDomain As AppDomain = AppDomain.CurrentDomain
   AddHandler currentDomain.UnhandledException, AddressOf
 MyHandler
   
   Try
      Throw New Exception("1")
   Catch e As Exception
      Console.WriteLine("Catch clause caught : " +
 e.Message)
   End Try
   
   Throw New Exception("2")

   ' Output:
   '   Catch clause caught : 1
   '   MyHandler caught : 2
End Sub 'Main


Sub MyHandler(sender As Object,
 args As UnhandledExceptionEventArgs)
   Dim e As Exception = DirectCast(args.ExceptionObject,
 Exception)
   Console.WriteLine("MyHandler caught : " + e.Message)
End Sub 'MyUnhandledExceptionEventHandler
using System;
using System.Security.Permissions;

public class Test {

   [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
   public static void Example()
   {
      AppDomain currentDomain = AppDomain.CurrentDomain;
      currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
      
      try {
         throw new Exception("1");
      } catch (Exception e) {
         Console.WriteLine("Catch clause caught : " + e.Message);
      }

      throw new Exception("2");

      // Output:
      //   Catch clause caught : 1
      //   MyHandler caught : 2
   }
   
   static void MyHandler(object sender, UnhandledExceptionEventArgs
 args) {
      Exception e = (Exception) args.ExceptionObject;
      Console.WriteLine("MyHandler caught : " + e.Message);
   }

   public static void Main()
 {
      Example();
   }
}
public ref class Test
{
private:
   static void MyHandler( Object^ /*sender*/,
 UnhandledExceptionEventArgs^ args )
   {
      Exception^ e = dynamic_cast<Exception^>(args->ExceptionObject);
      Console::WriteLine( "MyHandler caught : {0}", e->Message );
   }
public: 
   [SecurityPermissionAttribute( SecurityAction::Demand, ControlAppDomain = true
 )]
   static void Main()
   {
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   currentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(
 Test::MyHandler );
   try
   {
      throw gcnew Exception( "1" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Catch clause caught : {0}", e->Message );
   }

   throw gcnew Exception( "2" );
   
   // Output:
   //   Catch clause caught : 1
   //   MyHandler caught : 2
   }
};

int main()
{
   Test::Main();
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_AppDomain.UnhandledException イベント

COM オブジェクトに、AppDomain.UnhandledException イベントへのバージョンに依存しないアクセスが用意されています。

このイベントは、CLS に準拠していません。  

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Event UnhandledException As UnhandledExceptionEventHandler
Dim instance As _AppDomain
Dim handler As UnhandledExceptionEventHandler

AddHandler instance.UnhandledException, handler
event UnhandledExceptionEventHandler UnhandledException
event UnhandledExceptionEventHandler^ UnhandledException {
    void add (UnhandledExceptionEventHandler^ value);
    void remove (UnhandledExceptionEventHandler^ value);
}
/** @event */
void add_UnhandledException (UnhandledExceptionEventHandler value)

/** @event */
void remove_UnhandledException (UnhandledExceptionEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

詳細については、AppDomain.UnhandledException イベントのトピックを参照してください。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「AppDomain.UnhandledException」の関連用語

AppDomain.UnhandledExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AppDomain.UnhandledExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS