Good Exception Management Rules of Thumb - Back to Basics Edition
Almost five years ago I posted this "Good Exception Management Rules of Thumb" and had some interesting and useful comments. As with all lists of rules of thumbs, they may no longer be valid. What do you think?
Cori Drew commented to me in an email that she often sees code like this in the wild (changed to protect the innocent 3rd parties). This kind of code inevitably shows up in a file called Utils.cs, which may be your first clue there's trouble.
public void HandleException(String strMessage)
//Log to trace file only if app settings are true
if (Properties.Settings.Default.TraceLogging == true)
TraceSource objTrace = new TraceSource("YadaYadaTraceSource");
objTrace.TraceEvent(TraceEventType.Information, 5, strMessage.ToUpper());
//do nothing if there was an error
throw new Exception(Environment.NewLine + strMessage);
What's wrong with this code, Dear Reader?
There's a number of things that we can learn from, so have at it in the comments in nice lists bulleted with asterisk, won't you? You can comment on lines, or the larger strategy or both. I'll update the post with a roll-up once you come up for breath.