Skip to main content

Figuring out what went wrong

Posted by daniel on October 6, 2003 at 5:15 AM PDT

All of a sudden it seems as if everyone is talking about exceptions. Recent featured articles on have
recommended everything from using them in a fine grained way to turning to a scripting language when you just need to get something done and don't want to worry about types or exceptions.

In Also in Java Today we link to Paul Philion's JavaWorld article Beware the dangers of generic Exceptions . His advice is simple but he backs it up with examples of what can go wrong in each case:

  • Don't ignore exceptions
  • Don't catch generic Exception s
  • Don't throw generic Exception s

In the first case, he discusses the dangers of ignoring exceptions and then shows how and when you might do so if necessary.

The important thing about ignoring exceptions is ensuring that only a single method is wrapped in the ignoring try/catch block (so other methods in the enclosing block are still called) and that a specific exception is caught.

A problem with catching generic exceptions is that you end up with code that "catches exceptions it never intended to catch". In particular you will catch subclasses of RuntimeException. One exception is when you want "to prevent a single exception from stopping an entire system. In situations where requests, transactions, or events are being processed in a loop, that loop needs to continue to process even when exceptions are thrown during processing. "

There are times when you write a line or two of code that could throw three or more exceptions. It is tempting to throw a generic Exception to clean up the code, but Paul writes

even if the code is a little messy, at least it is explicit. Using the specific exception avoids a couple of very real problems: Throwing a generic Exception hides the details of the underlying problem, thus removing the opportunity to deal with the real problem. Further, throwing a generic Exception forces any call to that method to either catch that generic Exception (which has problems, as discussed previously) or propagate the problem by rethrowing that generic Exception .

We also link to John Zukowski's developerWorks article on SpringLayout Manager . John shows how to use this simpler alternative to the GridBagLayout to end up with attractive and flexible results in your Swing component design.

Michael Champion's Weblog entry Reports of the "Demise of the XML Database" are dubious says that SML DBMS has "been declared dead by those who would prematurely appropriate its inheritance." After explaining why he thinks the technology is still viable, Michael concludes with the warning that "it's important to consider the gap between technology mindshare among pundits and analysts, and technology deployment by businesses who need to get the job done efficiently and reliably.

In All things Blinky James Todd writes about performing routine actions remotely. He points to the Global Light Blinker project that aims to "create a world-wide JXTA GlobalLightBlinker PeerGroup which will allow people to experiment with remotely controlling embedded devices through the internet. "

Today in Projects and Communities, the Java Games community points to an article that says Games suffer from 'geek stereotype'. On the plus side the article argues that games have the "potential to change people's lives, offering them the chance to experience a wide range of emotions in a safe environment." The Java Web Services and XML community wiki features a page on the JAXb project . The page includes an introduction with feedback requesting for more details. Help provide a more complete introduction to JAXb.

In today's News Headlines :

Registered users can submit news items for the href=""> News Page using our
news submission form.
All submissions go through an editorial review by news director Steve
Mallet before being posted to the site. You can also subscribe to the href=""> News RSS

Current and upcoming Java Events:

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission form.
All submissions go through an editorial review before being posted to the

This blog is delivered weekdays as the href="">Java Today RSS
feed. Once this page is no longer featured as the front page of href=""> Java Today it will be archived at href=""> You can
access other past issues in the href=""> Archive.