Wednesday, November 21, 2007

exceptions?

As a still relatively new Java programmer, I'm still having trouble deciding whether or not to throw Exceptions in parts of my code that can go wrong.
This site is a great reference for what to do and what to avoid.


http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html



The most useful part: Antipatterns: what you really *shouldn't* do, and why. Here's an excerpt:


catch (NoSuchMethodException e) {
LOG.error("Blah", e);
throw e;
}


"This is one of the most annoying error-handling antipatterns. Either log the exception, or throw it, but never do both. Logging and throwing results in multiple log messages for a single problem in the code, and makes life hell for the support engineer who is trying to dig through the logs."

So true!!

I gotta get a me whole book of antipatterns....

No comments: