But how do you create an event handler for the Error event?
Given that the ASP.NET runtime raises its Error event whenever an unhandled exception occurs, it follows that the code for logging the error's details would go in an event handler. If you want to run some code when the visitor clicks a particular Button, you create an event handler for that Button's Click event and put your code there. As an ASP.NET developer you are accustomed to thinking in terms of events. Executing Code When The ErrorEvent Is RaisedĮvents provide an object a mechanism for signaling that something interesting has occurred, and for another object to execute code in response. The next two tutorials provide an overview of two such libraries. In cases where you only need to log the exception and notify a developer, using an error logging library is the way to go. The information examined in this tutorial is most useful if you need to process unhandled exceptions in some unique or customized manner. The two tutorials following this one explore error logging libraries that, after a bit of configuration, will automatically notify developers of runtime errors and log their details.
This tutorial shows how to access the details of an unhandled exception so that they can be logged and a developer notified. Furthermore, the error's details should be logged so that the error can be examined and diagnosed at a later point in time. When an error occurs in an application in production, it is important that the developers are notified of the error so that they can unearth the cause of the exception and address it. Using a human-friendly custom error page that matches the look and feel of the site is preferred to the default Runtime Error YSOD, but displaying a custom error page is only one part of a comprehensive error handling solution. In the preceding tutorial we configured the application to use a custom error page for remote users and the Exception Details YSOD for users visiting locally. There are three different types of error pages: the Runtime Error Yellow Screen of Death (YSOD) the Exception Details YSOD and custom error pages. When an unhandled exception occurs in an ASP.NET application, it bubbles up to the ASP.NET runtime, which raises the Error event and displays the appropriate error page. This tutorial provides an overview of how ASP.NET processes runtime errors and looks at one way to have custom code execute whenever an unhandled exception bubbles up to the ASP.NET runtime. When a runtime error occurs on a web application in production it is important to notify a developer and to log the error so that it may be diagnosed at a later point in time.
View or download sample code ( how to download)