views:

386

answers:

1

Hi,

I've got an ASP.NET MVC application that is supposed to catch all unhandled exceptions within the global.asax application error handler.

If I define the handler as follows:

protected void Application_Error(object sender, EventArgs e)

then it works fine. However, if within the Application_Start event I try and do:

this.Error +=new EventHandler(Application_Error);

The actual event is never called.

Does anyone know why and if so what i'm doing incorrectly?

Thanks!

A: 

You shouldn't have to add to the error event explicitly; Application_Error should get called automatically by the framework.

Note, however, that you have to have customeErrors mode to be "On", otherwise it won't call the handler when you're in development.

Paul