Two days for an exception handler?
Published 8.14.2008 by ~mattg
That’s right, it took me about two days (minus an hour here or there) to complete our exception handler. I know, that seems like a fairly long time, but it was a bit more than I anticipated. Plus, I have a habit of going overboard on certain things, and this is most definitely one of them.
It’s actually a pretty slick little class. The guts of it are a few static methods which take an exception. From there, the class will categorize the exception based on type, display the message to the user, and log the exception to an XML log file as determined by the log level. Since we’re trying to get our application to run in .Net’s partial trust, I had to use the IsolatedStorage classes in order to save the XML.
The bulk of the work actually came in handling our “fatal” exceptions We expect exceptions of type ValidationException and ApplicationException, so we handle those with a simple message box and let the user get back to work. Other exceptions, however, are unrecoverable, so I created a dialog page that displays the error to the user and allows them to send the report (via web service) to us. Not only did I have to get the error dialog to work, but I had to re-style it, which took at least 4 or 5 hours.
Extras? Well, the the log level is also used to specify the number of stack frames that get written to the log. It also specifies whether or not our non-fatal exceptions get written to the log. I also took a few extra steps to “lock down” the class so it’s easy to use and not very easy to misuse.
So, see, I do work. ![]()
Filed under .NET Development