Dr. Dobb's Journal Febrruary, 2006
Tip #6: Dont Throw Logs
Other than in tornados, logs arent thrown. Theyre sawed, chopped, rolled, turned, burned, floated, and even writtenbut never thrown. This simple physics applies to programming as well. In other words, you shouldnt throw exceptions that have already been logged. And yet, Ive seen code such as this:
try {
// something that generates an exception
. . .
} catch( Exception x ) {
Logger.log(x);
throw x;
}
Bad. This will most likely result in seeing the same exception message at very different points in your programs execution. The problem is, its the same error!
Trying to debug this is confusing at best. It also sends an ambivalent and confusing message to the callers of your function. The pitcher is saying to the catcher, Ill log this now but, well, Im not sure it could be fatal perhaps you should deal with it, too? This isnt only weak minded; its also lazy and pathetic.
Benjamin Booth
http://www.benjaminbooth.com/