예제 #1
0
        /// <summary>
        /// Create an exception handler based on specified exception to handle.
        /// </summary>
        /// <param name="exception">The exception to handle.</param>
        /// <param name="postHandlingAction">A <see cref="PostHandlingAction"/> determining what action should occur after an exception is handled by the configured exception handling chain. </param>
        /// <returns>A <see cref="Func{TExceptionContext, Task}"/> representing the exception handler.</returns>
        public Func <ExceptionContext, Task> CreateExceptionHandler(Exception exception, out PostHandlingAction postHandlingAction)
        {
            Guard.ArgumentNotNull(exception, nameof(exception));
            ExceptionPolicyEntry policyEntry = this.GetPolicyEntry(exception.GetType());

            postHandlingAction = policyEntry.PostHandlingAction;
            return(async context =>
            {
                await this.PreHandler(context);

                await policyEntry.ExceptionHandler(context);

                await this.PostHandler(context);
            });
        }
예제 #2
0
 public async Task<Exception> HandleException(Exception exception, Guid handlingId)
 {
     ExceptionContext context = new ExceptionContext(Guard.ArgumentNotNull(exception, nameof(exception)), Guard.ArgumentNotNullOrEmpty(handlingId, nameof(handlingId)));
     ExceptionPolicyEntry policyEntry = this.GetPolicyEntry(exception.GetType());
     try
     {
         await this.PreHandler(context);
         await policyEntry.ExceptionHandler(context);
         await this.PostHandler(context);
         switch (policyEntry.PostHandlingAction)
         {
             case PostHandlingAction.ThrowNew: return context.Exception;
             case PostHandlingAction.ThrowOriginal: return context.OriginalException;
             default: return null;
         }
     }
     catch (Exception ex)
     {
         return new ExceptionHandlingException(Resources.ExceptionHandlingError, ex);
     }
 }