asp.net-mvc-4 - Controller 中的asp.net mvc异常未在自定义ErrorHandler上处理

标签 asp.net-mvc-4 error-handling

我有一个全局ErrorHanlder(从HandleErrorAttribute派生),可以正常工作并捕获发生的所有错误。但是我有一种情况,家庭 Controller 会抛出异常。我检查了一下,发现从 Controller 抛出的错误未在我的自定义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正在 Controller 的构造函数中初始化。 HandleError过滤器不处理在 Controller 构造期间引发的异常。

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

关于asp.net-mvc-4 - Controller 中的asp.net mvc异常未在自定义ErrorHandler上处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29877339/

相关文章:

c# - MVC4 Razor View header 中@model 和@inherit 的区别?

c# - 如何使用 C# 在运行时在 ASP.NET MVC 中动态添加行?

javascript - .json()用于错误处理的内容是什么?

asp.net - 用于错误处理和丢失图像的 HttpModule

python - 二微分方程组的 Runge-Kutta 实现

c# - MVC 表单模型为复杂对象集合返回 null

asp.net-mvc-4 - 从 mvc razor 页面的页面内容中删除 

php - 引用 - 这个错误在 PHP 中意味着什么?

asp.net-mvc - 当用户没有互联网时,是否可以从缓存中设置自定义错误页面

Asp.Net MVC 4 - ActionFilterAttribute 用法