{ by david linsin }

January 18, 2007

Effective Java Exceptions

I read Artima's summary of the article "Effective Java Exceptions" and I really like the categorization of Exceptions:
Contingency... is an expected condition demanding an alternative response from a method that can be expressed in terms of the method's intended purpose. The caller of the method expects these kinds of conditions and has a strategy for coping with them.

Fault [is] an unplanned condition that prevents a method from achieving its intended purpose that cannot be described without reference to the method's internal implementation...

Contingencies are expected and natural consequences of using [an] API. They do not represent a failure of the software or of the execution environment. Contrast these with actual failures that could arise due to problems related to the internal implementation details of [a class]...

Ruzek maps contingencies to Java checked exceptions and faults to subclasses of RuntimeException.

In most of my code I handle Exceptions the same way. If there is any way to recover from an failure I try to handle an Exception. In case there is no way to recover, I don't care and throw it as a wrapped Exception. In most cases though it's the latter. I've not experienced many case where you can really handle an Exception in a useful way, especially when it comes to web applications.

0 comments:


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...