プログラムで処理されていない例外をキャッチしようとしています。このコードをプログラムのメインクラスで使用しています。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.Run(new Form1());
}
public static void CurrentDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled domain Exception");
Application.Exit();
}
今度はフォームform1で、単純な例外を作成しようとします。trycatchブロックなしでゼロ除算を行うと、メインモジュールのコードが実際に例外をインターセプトしますが、MSVisualStudioダイアログが表示されます。アプリケーションは終了しません。もちろん、実際の状況では、エラーをログに記録/メールで送信します。しかし、例外をインターセプトした後も実行が継続する理由を理解したいのですが?ありがとう