示例#1
0
        public static void HandleException(Exception ex, string errorMessage = "Error: Unhandled exception", string errorMessageBoxDefaultTitle = "Error", string debugErrorMessagePrefix = "ERROR: ")
        {
            var eEx = ex as ErrorMessageException;

            if (eEx != null)
            {
                System.Diagnostics.Debug.WriteLine(debugErrorMessagePrefix + eEx.Message);

                if (eEx.DontShowAgainMessageBox)
                {
                    SHMessageBoxCheck(
                        IntPtr.Zero,
                        "Error: " + eEx.Message,
                        eEx.Title.Else(errorMessageBoxDefaultTitle),
                        MessageBoxCheckFlags.MB_OK | MessageBoxCheckFlags.MB_ICONEXCLAMATION,
                        0,
                        eEx.DontShowAgainMessageBoxId
                        );
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Error: " + eEx.Message, eEx.Title.Else(errorMessageBoxDefaultTitle));
                }
            }
            else
            {
                ExceptionCatcher.HandleException(ex, errorMessage);
            }
        }
示例#2
0
 public static void Do(Action action, string errorMessage = "Error: Unhandled exception", Action finallyAction = null, Action exceptionAction = null, string errorMessageBoxDefaultTitle = "Error", string debugErrorMessagePrefix = "ERROR: ", bool swallowOperationCancelled = false)
 {
     ExceptionCatcher.Do(() =>
     {
         try
         {
             try
             {
                 action();
             }
             catch (OperationCanceledException)
             {
                 if (!swallowOperationCancelled)
                 {
                     throw;
                 }
             }
         }
         catch (ErrorMessageException ex)
         {
             HandleException(ex, errorMessage, errorMessageBoxDefaultTitle, debugErrorMessagePrefix);
         }
     }, errorMessage, finallyAction, exceptionAction);
 }