Posted under .net & Code & Logging & Software Design
For better or worse, exceptions are a part of life. Any non-trivial application is going to generate them, at least occasionally, when something exceptional happens. One shouldn’t rely on exceptions for control of flow; return values are much better at this in many ways. And a person should run tests to prevent exceptions, when it’s possible … make sure a number isn’t zero before dividing by it.
When an exception, which is really just a modern term for an error, does rear its ugly head, in addition to handling it gracefully, most applications need to do something with it. This might involve showing a message to the user, logging the fact that a problem happened for later inspection, or any number of things. A new open-source .net expands your options.
ExpressionFormatter is a static class, written in C# and targeting the Microsoft.net framework v2, that turns a managed Exception object into an html stream. In an ASP.NET application this lets you send a detailed, easily readable message directrly to the client (after they’ve been authorized!), but in a middle-tier, server-based application html is a fantastic way to store exception details for later review and drill-down analysis. In a Windows Forms client, you can log the exception for later use, and when it makes sense to, you can display it to the client using either a WebBrowser control or by writing an html file and using Process.Start to launch it.