Brad Wilson has a response to my recent post. Here’s an excerpt:
I read Craig Andera's post about global error handling in .NET, and I thought I'd give an alternative implementation for global error handling.
We use a system like this to catch all unhandled exceptions, e-mail them to the admin, log them to the Event Log, and then give the user our own version of an "Internal System Error" page.
The HttpApplication object class contains an event called Error. This event is issued whenever an unhandled exception occurs. The exception that has been thrown is available via Server.GetLastError(). The easiest way to do this is by making a new class that overrides IHttpModule and registering it in Web.config, like so:
I like this a lot, and I think both techniques are valuable tools to have in your error handling arsenal – the way Fritz showed me gives you the ability to do per-page error handling, and Brad’s approach gives you application-level error handling. I plan to use both, especially since Brad’s way lets me catch more types of errors. On top of that, clever use of EIF can allow me to switch log messages for each of them on and off independently.