Windows Forms
Visual Studio 2012、C#、.NET 4.5 を使用してアプリケーションを作成しています。Windows 7。
未処理の例外を独自のエラー ハンドラで処理したいと考えています。以下に示すようなコードをいくつか書きました。エラー処理の 2 つの異なる方法も試しました。
このプログラムを Visual Studio (2012) 内で実行すると、非常にうまく動作します。
しかし、エクスプローラーからプログラムを起動すると、エラー ハンドラーが呼び出されません。代わりに、.NET Framework からの標準エラー ハンドラが常にポップアップ表示されます。
それで、私は何を間違っていますか?
static void Main()
{
try
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(HandleUnhandledException);
Application.Run(new frmMainFrame());
}
catch (Exception ex)
{
// Here is my error handler ....
}
}
static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
Exception ex = (Exception) args.ExceptionObject;
// Here is my error handler ....
}