This is done to help you debug unhandled exceptions. ShowDialog () is special, this method does not return until you close the dialog. It becomes as modal as when you start another dispatcher loop, the exact equivalent of Application.Run ().
, , ( ), Application.UnhandledException. , . , , . . , , , .
, catch . , .
, Main(), UnhandledExceptionMode.ThrowException Application.SetUnhandledExceptionMode(). , , , . , , . AppDomain.CurrentDomain.UnhandledException, , , . :
[STAThread]
static void Main() {
if (!System.Diagnostics.Debugger.IsAttached) {
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
MessageBox.Show(e.ExceptionObject.ToString());
AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
Environment.Exit(1);
}
catch . , catch-em-all. . , , , . , . Debug > Windows > Exception Settings > " ", .