ErrorHandling in asp.net web api
2021-06-18 16:18
标签:roc oid contain .com from ges stop api nec https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/web-api-global-error-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). https://stackoverflow.com/questions/22038800/can-anyone-explain-the-work-flow-of-iexceptionhandler-with-sample-client-applica Source on NuDoq: ExceptionHandlerContext and ExceptionContextCatchBlock ErrorHandling in asp.net web api 标签:roc oid contain .com from ges stop api nec 原文地址:https://www.cnblogs.com/chucklu/p/10304032.htmlSolution Overview
When to Use
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;
}
}
CatchBlock.IsTopLevel
IsOutermostCatchBlock
does not exists. Use CatchBlock.IsTopLevel
instead:public virtual bool ShouldHandle(ExceptionHandlerContext context)
{
return context.ExceptionContext.CatchBlock.IsTopLevel;
}
文章标题:ErrorHandling in asp.net web api
文章链接:http://soscw.com/essay/95549.html