/// <summary> /// Initializes a new instance of the <see cref="ExceptionContext"/> class using the values provided. /// </summary> /// <param name="exceptionInfo">The exception caught.</param> /// <param name="catchBlock">The catch block where the exception was caught.</param> /// <param name="context">The context in which the exception occurred.</param> public ExceptionContext(ExceptionDispatchInfo exceptionInfo, ExceptionContextCatchBlock catchBlock, CommandHandlerContext context) { if (exceptionInfo == null) { throw new ArgumentNullException("exceptionInfo"); } this.ExceptionInfo = exceptionInfo; if (catchBlock == null) { throw new ArgumentNullException("catchBlock"); } this.CatchBlock = catchBlock; if (context == null) { throw new ArgumentNullException("context"); } this.Context = context; CommandHandlerRequest request = context.Request; if (request == null) { throw Error.ArgumentNull(Resources.TypePropertyMustNotBeNull, typeof(HandlerRequest).Name, "Request", "context"); } this.Request = request; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionContext"/> class using the values provided. /// </summary> /// <param name="exceptionInfo">The exception caught.</param> /// <param name="catchBlock">The catch block where the exception was caught.</param> /// <param name="request">The request being processed when the exception was caught.</param> /// <param name="response">The repsonse being returned when the exception was caught.</param> public ExceptionContext(ExceptionDispatchInfo exceptionInfo, ExceptionContextCatchBlock catchBlock, CommandHandlerRequest request, HandlerResponse response) { if (exceptionInfo == null) { throw new ArgumentNullException("exceptionInfo"); } this.ExceptionInfo = exceptionInfo; if (catchBlock == null) { throw new ArgumentNullException("catchBlock"); } this.CatchBlock = catchBlock; if (request == null) { throw new ArgumentNullException("request"); } this.Request = request; if (response == null) { throw new ArgumentNullException("response"); } this.Response = response; }
public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) { if (context != null) { ExceptionContext exceptionContext = context.ExceptionContext; ExceptionContextCatchBlock catchBlock = exceptionContext.CatchBlock; if (catchBlock != null && catchBlock.IsTopLevel) { context.Result = CreateDefaultLastChanceResult(exceptionContext); } } return(this.innerHandler.HandleAsync(context, cancellationToken)); }
/// <summary>Determines whether the exception should be handled.</summary> /// <param name="context">The exception handler context.</param> /// <returns> /// <see langword="true"/> if the exception should be handled; otherwise, <see langword="false"/>. /// </returns> /// <remarks>The default decision is only to handle exceptions caught at top-level catch blocks.</remarks> public virtual bool ShouldHandle(ExceptionHandlerContext context) { if (context == null) { throw Error.ArgumentNull("context"); } ExceptionContext exceptionContext = context.ExceptionContext; ExceptionContextCatchBlock catchBlock = exceptionContext.CatchBlock; if (catchBlock == null) { throw Error.ArgumentNull("context", Resources.TypePropertyMustNotBeNull, typeof(ExceptionContext), "CatchBlock"); } return(catchBlock.IsTopLevel); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionContext"/> class using the values provided. /// </summary> /// <param name="exceptionInfo">The exception caught.</param> /// <param name="catchBlock">The catch block where the exception was caught.</param> /// <param name="request">The request being processed when the exception was caught.</param> public ExceptionContext(ExceptionDispatchInfo exceptionInfo, ExceptionContextCatchBlock catchBlock, CommandHandlerRequest request) { if (exceptionInfo == null) { throw new ArgumentNullException("exceptionInfo"); } this.ExceptionInfo = exceptionInfo; if (catchBlock == null) { throw new ArgumentNullException("catchBlock"); } this.CatchBlock = catchBlock; if (request == null) { throw new ArgumentNullException("request"); } this.Request = request; }