On Wed, Mar 23, 2011 at 2:43 PM, phil swenson <[email protected]>wrote:

> I never thought I'd see anything useful on an OSGi blog, but today I saw
> this:
>
> http://www.osgi.org/blog/2011/03/exception-hygiene.html
>
> So if you accept that CheckedExceptions are a bad idea... read the comments
> on this post.  There is a debate as to how to handle the atrocity that the
> CheckedException.  There are two approaches that are debated:
>
> 1)
> void foo() {
>     try {
>         bar();
>     } catch( Exception e) {
>         throw new RuntimeException(e);
>     }
> }
>
> 2)
> void foo() throws Exception {
>     bar();
> }
>
> I used to be in the #1 camp.  But after reading the thread, I'm thinking
> that just putting throws Exception everywhere might be easier/more
> pragmatic.  It's uglier, but it does make the stack dump more readable I
> think.
>

I'm quite baffled by the justifications here. All this hacking just so the
stack dump is more readable? Is that really what you care the most about?

I care about my code being robust, which means handling errors in a sensible
way. Sometimes, it means catching them and/or wrapping them, other times it
means declaring them in my throws clause and letting the code above deal
with what happened. This should be the only deciding factor in how you want
to handle checked exceptions.

What you (and the author of the blog post) are advocating is basically "I'm
too lazy to handle errors so I'm just going to ignore them". The author of
the post even has the nerve to say "It's amazing how readable your code
becomes". Well, yes, if you start ignoring error cases, your code becomes
much simpler.

Instead of just putting a blanket ban on all checked exceptions, he would
have been better off trying to understand which ones need to be checked and
which ones should be unchecked. All he's done with his fork is making the
servlet less robust.

Checked exceptions are a good idea and an indispensable component of robust
software, but they are easy to misuse.

-- 
Cédric

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to