1

I am experimenting with the relationship between Elmah and MVC's plumbed in exception handling, and am surprised at the outcome of the following code. This is a brand new, straight from project template MVC application, and I have only added Elmah modules and handlers to the web.config. And of the course the 'throw':

[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
        throw new Exception("Just for you Elmah!");
        return View();
    }

Break when error is thrown is set to off, yet the debugger still breaks. When I continue I get a YSOD, and an Elmah error log, but it seems HandleError is doing nothing.

JUST IN I didn't think I had to have custom errors turned on, as I thought that was only for 'my' unhandled errors. I guess MVC is just as much a client of that service as I am.

1

2 Answers 2

3

So to start ASP.net MVC [HandleError] not catching exceptions and then onto the logging How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?

Sign up to request clarification or add additional context in comments.

Comments

0

Check HandleErrorAttribute is added to the GlobalFiltersCollection in the Global.asax.cs

public static void RegisterGlobalFilters(GlobalFiltersCollection filters)
{
  filters.Add(new HandleErrorAttribute());
}

1 Comment

Applying the filter globally is the equivalent of adding the attribute to each action. If I apply it to only one action and it doesn't work, applying it to all actions will only have it not working everywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.