Implement page-level or application-level error handlers

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Alex Mackman, Michael Dunner, Srinath Vasireddy, Ray Escamilla and Anandha Murukan

If you need to trap and process unhandled exceptions at the page level, create a handler for the Page_Error event that is similar to the one shown below.

public void Page_Error(object sender,EventArgs e)
 // Get the source exception details
 Exception ex = Server.GetLastError();
 // Write the details to the event log for diagnostics
 . . .
 // Prevent the exception from propagating and generating an 
 // application level event (Application.Error)

If exceptions are allowed to propagate from the page handler or there is no page handler, an application error event is raised. To trap application-level events, implement Application_Error in Global.asax, as follows:

protected void Application_Error(Object sender, EventArgs e) 
 //  Write to the event log.


Personal tools