/// <summary>
 /// Runs the given <seealso cref="Action"/> and handles all non-critical exceptions by showing an
 /// error dialog to the user. If the exception is critical, as determiend by <seealso cref="ErrorHandler.IsCriticalException(Exception)"/>
 /// then it is re-thrown as this could be that the process is not in a good state to continue executing.
 /// </summary>
 /// <param name="action"></param>
 public static void HandleExceptions(Action action)
 {
     try
     {
         action();
     }
     catch (AggregateException ex)
     {
         Debug.WriteLine($"Uncaught aggregate exception: {ex.Message}");
         if (ErrorHandler.ContainsCriticalException(ex))
         {
             throw;
         }
         EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex));
         UserPromptUtils.ExceptionPrompt(ex);
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Uncaught exception: {ex.Message}");
         if (ErrorHandler.IsCriticalException(ex))
         {
             throw;
         }
         EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex));
         UserPromptUtils.ExceptionPrompt(ex);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Returns whether the given <paramref name="ex"/> is a critical exception according to the
 /// <seealso cref="ErrorHandler"/> determination. Handles correctly the case of a normal exception vs.
 /// an <seealso cref="AggregateException"/>.
 /// Critical exceptions should not be handled by the extension code as typically they mean that the execution
 /// environment is no longer suitable.
 /// </summary>
 /// <param name="ex">The exception to check.</param>
 /// <returns>True if the exception is critical, false otherwise.</returns>
 public static bool IsCriticalException(Exception ex)
 {
     if (ex is AggregateException)
     {
         return(ErrorHandler.ContainsCriticalException(ex as AggregateException));
     }
     else
     {
         return(ErrorHandler.IsCriticalException(ex));
     }
 }