| Author |
catch Throwable
|
Michael Imhof
Greenhorn
Joined: Nov 07, 2004
Posts: 24
|
|
A lot of java programmers just use following code for exception handling I would like to hear your opinion about this overall exception catching. In my opinion it's dirty programming but I never found a good argument to proof this. Do you know examples where it's really important to catch Throwable (that means catching Error, RuntimeException, ...)??? Regards Michael
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
In general, catching Throwable is not the right thing to do. A java.lang.Error usually indicates a very bad situation that means "all bets are off". I like to let Error, and often RuntimeException, percolate up as far as possible in code. However, it may be worth catching either or both at the top of the call-stack, in main() of the application, or run() of the thread. This particularly if you want to do some logging or something. Extra-special care should be taken of OutOfMemoryError, because this is a particularly bad Error. Squashing that is almost always going to be a bad idea. If I see code that liberally sprinkles catch(Exception e) or catch(Throwable t), I tend to suspect that the programmer could not be bothered to think about error handling. In a quick-and-dirty utility, that can be excused; in industrial-strength code, it can't.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
Nice answer!
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: catch Throwable
|
|
|