The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Three Rules for Effective Exception Handling
Subject:  Every rule has an exception*
Date:  2003-12-09 13:46:58
From:  jimothy
Response to: Rethrowing exceptions is not the best idea....


Like any rule, these rules may be broken when there is a good reason for doing so, and when the rule-breaker is aware of the consequences.

My observation is the vast majority of programmers (that I have worked with) misunderstand effective exception handling. They catch exceptions much too soon (right where the compiler complains about it), use generic catch (Exception e) blocks, and either ignore or do nothing more than log the error.

I offer these rules in hope of breaking those habits. Once you've gained enough understanding of exceptions in Java to debate the rules (as you have), you're qualified to break them (with care) when you see fit, because you do understand the consequences. But the average programmer may not, and for them, it is important for them to be aware of these rules.

Thanks for your feedback. It's interesting that with all that has been written on Java exceptions, there's always new insight available.

* pun intended

 Feed java.net RSS Feeds