https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling
We provide two new user-replaceable services, IExceptionLogger and IExceptionHandler, to log and handle unhandled exceptions. The services are very similar, with two main differences:
Both services provide access to an exception context containing relevant information from the point where the exception was detected, particularly the HttpRequestMessage, the HttpRequestContext, the thrown exception and the exception source (details below).
public class ExceptionHandler : IExceptionHandler { public virtual Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) { if (!ShouldHandle(context)) { return Task.FromResult(0); } return HandleAsyncCore(context, cancellationToken); } public virtual Task HandleAsyncCore(ExceptionHandlerContext context, CancellationToken cancellationToken) { HandleCore(context); return Task.FromResult(0); } public virtual void HandleCore(ExceptionHandlerContext context) { } public virtual bool ShouldHandle(ExceptionHandlerContext context) { return context.ExceptionContext.CatchBlock.IsTopLevel; } }
IsOutermostCatchBlock does not exists. Use CatchBlock.IsTopLevel instead:
public virtual bool ShouldHandle(ExceptionHandlerContext context) { return context.ExceptionContext.CatchBlock.IsTopLevel; }
Source on NuDoq: ExceptionHandlerContext and ExceptionContextCatchBlock