クラスで未処理の例外をすべて処理したいのでProgress
、エラー ログ用のコードをいくつか書きました。
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginPoint());
}
catch (Exception myException)
{
//log the unhandled exceptions.
}
}
}
しかし、の例外はBackgroundWorker
正しく処理されていません:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
throw new Exception("TEST EXCEPTION!");
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
throw new Exception("I GOT THE EXCEPTION");
}
}
クラスで例外「I GOT ...」を処理したいのですProgress
が、アプリケーションを実行 (デバッグではなく) すると、システムの例外ダイアログが表示されます。