catch
WinForms アプリケーションに次のグローバル例外を実装しました。
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 MyMainForm());
}
catch (Exception ex)
{
MessageBox.Show("UNHANDLED EXCEPTION: The program will be terminated. Details follow:\n\n" +
getExceptionInfoWithDebuggerOutput(ex),
"Global Exception",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
次に、コードの下で、例外が発生します (このようなもの-完全に私の物忘れが原因です):
public partial class MyPage : UserControl
{
void func1()
{
SqlConnectionStringBuilder conStr = null;
//... later
conStr.DataSource = strServer; //<<--- Where exception is raised
}
}
ここで、プロジェクトをデバッグしている場合Global Exception
、グローバル例外ハンドラーからのメッセージ ボックスが表示されます。
しかし、プロジェクトをデバッグせずに Ctrl+F5 として実行した場合、またはリリース プロジェクトをビルドした場合、上記でコーディングしたウィンドウではなく、次のウィンドウが表示されます。
グローバル例外ハンドラーに代わりに処理をさせる方法はありますか?