Figuring out what went wrong
Posted by daniel on October 06, 2003 at 05:15 AM | Comments (5)
All of a sudden it seems as if everyone is talking about exceptions. Recent featured articles on java.net 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 java.net News Headlines :
Registered users can submit news items for the java.net 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 java.net News RSS
feed.
Current and upcoming Java Events:
Registered users can submit event listings for the java.net Events Page using our events submission form.
All submissions go through an editorial review before being posted to the
site.
This blog is delivered weekdays as the Java Today RSS
feed. Once this page is no longer featured as the front page of Java Today it will be archived at
http://today.java.net/today/archive/index_10062003.html. You can
access other past issues in the java.net Archive.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
All execptions are not equal
When logging exceptions, use logging levels. Even an exception that you intend to ignore when logged in lower level will help when troubleshooting some serious problems.
---------------------------------
http://javarss.com
Just one bookmark - for all java news, articles and blogs.
----------------------------------
Posted by: architect on October 06, 2003 at 08:28 AM
-
All execptions are not equal
Speaking of logging, one thing I'd warn against doing what Paul Philion does one place in his JavaWorld artcile: Both log and throw an exception. Paul just logs e.toString() before re-throwing the exception, but I've seen examples like this:
....
catch (SomeException e)
{
e.printStackTrace();
throw e;
}
Why is this so bad? Because if A calls B calls C calls D, and they each log and re-throw the exception, one error looks like four in the log file, and leads to "scroll blindness."
I've written an article (a work-in-progress) I call Exception Horror Stories, for those interested: http://homepage.mac.com/jimothy/articles/exceptionHorror.html
Posted by: jimothy on October 06, 2003 at 02:51 PM
-
All execptions are not equal
This is a valid point, but...
The main reason I suggest the stack trace is because I've seen too many times an exception get caught but nothing done about it. I guess my real point is: If you catch an exception, do somthing with it!
So, in most cases, if you are simply re-throwing the exception there is not a burning need to log it.
A couple of notes, though:
Use a logging package that allows you to turn stacktraces on and off. This wouldn't be a problem, though you would still get 4 error logs for the same problem.
DO log the situation where you are wrapping the exception in another exception to be thrown. (Aside: Is there a name for the pattern of "re-casting" an exception?) I think this is important as there might be crutial information in the original exception.
Posted by: philion on June 15, 2004 at 09:52 AM
-
wow power leveling
wow powerleveling
wow power leveling
wow gold
wow items
feelingame.com
wow tips
Most Valuable WOW Power Leveling Service
wow power leveling faq
cheap wow power leveling
wow power leveling
wow powerleveling
wow power lvl
Posted by: wowleveling3 on December 14, 2007 at 02:10 AM
-
网络营销软件
网络营销软件
网络营销软件
群发软件
群发软件
---
群发软件
网络营销软件
论坛群发软件
网站排名软件
群发软件
推广小助手破解版
论坛群发软件
网站排名软件
群发软件
网络营销软件
网站推广软件
信息群发软件
论坛群发软件
信息群发软件
博客群发软件
qq群发软件
邮件群发软件
博客群建软件
企业名录搜索软件
信息群发软件
邮件群发软件
论坛群发软件
博客群发软件
网站推广软件
网络营销软件
全能营销破解版
Posted by: bininine on December 16, 2007 at 09:20 AM
|