IsFatalException() 공개 정적인 메소드

Convience function for those that are not availability aware to quickly test if they should rethrow.
The question is where in the catch clause to put the test, at the beginning of the catch or at the end. Sometimes we do important cleaning in the catch clause plus notification of other threads. In doubt do the throw at the end of the exception handling.
public static IsFatalException ( Exception ex ) : bool
ex System.Exception
리턴 bool
예제 #1
0
파일: AppHelper.cs 프로젝트: sdraht/moni
 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);
             }
         }
     }
 }
예제 #2
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);
                    }
                }
            }
        }