asp.net 自定义 ErrorHandler 未处理控制器中的 mvc 异常

asp.net mvc exception in controller not beign handled at custom ErroHandler

我有一个全局 ErrorHanlder(派生自 HandleErrorAttribute)可以正常工作并捕获所有发生的错误。但是我有一种情况,家庭控制器可以抛出异常。我检查并发现我的自定义 ErrorHandler 没有处理从控制器抛出的错误,asp.net 给出了这个:

Exception of type 'Exception' was thrown.

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

你能帮帮我吗?

代码:

    public HomeController()
            {

                    _ServiceAsync = new ServiceAsyncProvider();

            }

class ServiceAsyncProvider
{
   public ServiceAsyncProvider()
     {
            throw new Exception(); 
     }
}

虽然您的代码片段在这一点上有点不清楚,但看起来您的 _ServiceAsync 正在控制器的构造函数中初始化。 HandleError 过滤器不处理控制器构造期间抛出的异常。

有关详细信息,请参阅此相关问题:Handling Exceptions that happen in a asp.net MVC Controller Constructor

您在构造函数中抛出异常。过滤器不处理这些异常。