I'm mostly in the rethrow-as-checked camp.

One note: while I tend to consider a catch(Exception) to be a major 
no-no, I believe a catch(Throwable) can be useful sometimes. As example: 
I maintain a little indexing tool based on Lucene, and when indexing a 
document I tend to do a catch(Throwable): the indexing tools sometimes 
fail and the only thing I want to do is to log and continue. In every 
case where there is a separate task running whose failure is not 
critical to the rest of the system, catch(Throwable) seems right to me. 
You want to include the dreaded OutOfMemoryError, so don't catch Exception.

Of course you still can't rely on being safe this way -- the 
OutOfMemoryError can hit other parts of the code and I actually had a 
library call System.exit(..) on me.

I guess the totally right thing would be spawning a new process, but 
that's just too expensive. Catching Throwable seems a reasonable 
compromise. But of course only if your system is not too critical to 
begin with.

  Peter



Hannu Leinonen wrote:
> Hello posse (of The Posse)!
>
>
> I've been lately discussing about exception handling in Java with my 
> workmates. And I've noticed that there's some uncertainty about 
> Exceptions and how to use them. Currently we're working on a quite 
> traditional three-tier Spring+Hibernate web app (using way too much of 
> that disgusting null programming, but that's another story).
>
> Personally I usually regard ... catch (Exception e) ... as a code smell 
> because it will catch - usually unintentionally - all RuntimeExceptions 
> too. Not to mention catching Throwable, like there was a lot we could do 
> with Errors. My current style is catching all checked exceptions on 
> their own blocks and catching RuntimeException on it's own block where 
> it makes sense (at least in controllers). But that sometimes makes the 
> code ugly with a dozen catch blocks doing exactly the same thing. AFAIK 
> Project Coin is going to fix this annoyance. Would it be better in a 
> situation where I anyways catch RuntimeException to use Exception as it 
> is the lowest common denominator?
>
> How do you make the most out of your Exceptions? And how do you do it in 
> multi-tier architecture?
>
>
> Best Regards,
> Hannu
>
> >
>   


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

Reply via email to