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 イベントトピック参照してください

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



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「AppDomain.UnhandledException」の関連用語

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

   

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



AppDomain.UnhandledExceptionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS