Beispiel #1
0
        public static bool ReportAndCatchUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
        {
            if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken) || exception is OperationCanceledIgnoringCallerTokenException)
            {
                return(false);
            }

            return(ReportAndCatch(exception, severity));
        }
Beispiel #2
0
        public static bool ReportAndPropagateUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
        {
            if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken))
            {
                return(false);
            }

            return(ReportAndPropagate(exception, severity));
        }
Beispiel #3
0
 internal static Action <TInput1, TInput2, CancellationToken> WrapUserAction <TInput1, TInput2>(this Action <TInput1, TInput2> userAction)
 {
     return((input1, input2, token) =>
     {
         try
         {
             userAction(input1, input2);
         }
         catch (Exception e) when(!ExceptionUtilities.IsCurrentOperationBeingCancelled(e, token))
         {
             throw new UserFunctionException(e);
         }
     });
 }
Beispiel #4
0
 internal static Func <TInput, CancellationToken, TOutput> WrapUserFunction <TInput, TOutput>(this Func <TInput, CancellationToken, TOutput> userFunction)
 {
     return((input, token) =>
     {
         try
         {
             return userFunction(input, token);
         }
         catch (Exception e) when(!ExceptionUtilities.IsCurrentOperationBeingCancelled(e, token))
         {
             throw new UserFunctionException(e);
         }
     });
 }
Beispiel #5
0
        public static bool ReportIfNonFatalAndCatchUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
        {
            if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken))
            {
                return(false);
            }

            if (!HandlerIsNonFatal)
            {
                // We'll catch the exception, but we won't report anything.
                return(true);
            }

            return(ReportAndCatch(exception, severity));
        }