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.

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 2
    http://stackoverflow.com/questions/619582/asp-net-mvc-handleerror-not-catching-exceptions – Ahmad Aug 02 '10 at 19:20

2 Answers2

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?

Community
  • 1
  • 1
Ahmad
  • 22,657
  • 9
  • 52
  • 84
0

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

public static void RegisterGlobalFilters(GlobalFiltersCollection filters)
{
  filters.Add(new HandleErrorAttribute());
}
Prabhat
  • 65
  • 4
  • 3
    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. – ProfK Jan 31 '14 at 02:14