嗨,我在 ApiController 中遇到异常处理问题。
我将 Ninject 拦截器绑定到控制器操作,问题是拦截器永远不会看到控制器中/下面抛出的任何异常。
public class ControllerInterceptor : IInterceptor
{
private DbContextTransaction transaction;
public void Intercept(IInvocation invocation)
{
try
{
invocation.Proceed() // action will throw exception for sure
}
catch (Exception) // never executes even if there was exception in Proceed
{
throw;
}
}
}
}
我唯一的想法是 ApiController 捕获所有异常并且从不转发它们,因此对于拦截器来说,一切看起来都没有发生。任何人都可以证实这一点。