public static IsFatalException ( |
||
ex | ||
리턴 | bool |
public static void HandleUnhandledException(object exception, bool exitProgram) { // only allow one thread (UI) lock (lockErrorDialog) { try { // check for special exitprogram conditions if (!exitProgram) { exitProgram = ExceptionExtensions.IsFatalException((Exception)exception); } // prevent recursion on the message loop if (!blockExceptionDialog) { blockExceptionDialog = true; // only log once. Otherwise it is poosible to file the file system with exceptions (message pump + exception) logger.Fatal("UnhandledException: {0}\n\n\nAt Stack: {1}", exception, Environment.StackTrace); try { // we do not switch to the UI thread, because the dialog that we are going to show has its own message pump (all dialogs have). // As long as the dialog does not call methods of other windows there should be no problem. if (exception == null) { //TS_StackTraceBox.ShowStackTraceBox("Unhandled Exception Occurred", Environment.StackTrace); } else if (exception is Exception) { //TS_ExceptionBox.ShowErrorBox((Exception)exception); } else { // won't happen really - exception is really always of type Exception //TS_StackTraceBox.ShowStackTraceBox("Unhandled Exception Occurred: " + exception, Environment.StackTrace); } } finally { if (!exitProgram) { blockExceptionDialog = false; } } } } catch (Exception e) { logger.Fatal(e, "Unable to Handle UnhandledException"); } finally { if (exitProgram) { logger.Warn("Application exits due to UnhandledException"); Environment.Exit(0); } } } }
public static void HandleUnhandledException(object exception, bool exitProgram) { if (Debugger.IsAttached) { // When debugging or running unit tests, let the unhandled exception surface. return; } // only allow one thread (UI) lock (lockErrorDialog) { try { // check for special exitprogram conditions if (!exitProgram) { exitProgram = ExceptionExtensions.IsFatalException((Exception)exception); } // prevent recursion on the message loop if (!blockExceptionDialog) { blockExceptionDialog = true; try { // only log once. Otherwise it is possible to fill the file system with exceptions (message pump + exception) LogFatalException("UnhandledException", exception as Exception); } finally { if (!exitProgram) { blockExceptionDialog = false; } } } } catch (Exception ex) { LogFatalException("Unable to handle UnhandledException", ex); } finally { if (exitProgram) { logger.Fatal($"Application exits due to UnhandledException, after uptime:{TimeSpanUtil.UptimeString(AppHelper.Instance.AppStartedUtcTime)}"); Environment.Exit(0); } } } }