Exceptions: How to make sure... 2006-11-01 - By Ian Vellosa
Back Mike,
RuntimeException is an extension of Exception:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/RuntimeException.html
Therefore, catching Exception will also catch things like NullPointers.
When you catch Throwable you will also catch Errors. 99.9% of the time you do not want to do this (well I don't) as you will have no idea how to deal with something like a OutOfMemoryError. So just catchng at the Exception level is fine.
What you say about a good IDE, like eclipse, to help identify which exceptions are going to be thrown is very true. And in this case that is the easiest answer - sounds like he's not going to read the APIs to see what they throw...
--- Mike New <mike@(protected)> wrote:
> > Hi list, how make sure I can handle (catch) every exception that > > a statement may throw; I mean, I can add: > > > > // proof code > > } catch (Exception anyException) { > > // handle it generically > > } > > > > But what I really want to know is how many and which are the > > exceptions that a statement may throw...thanks in advance > > I use Eclipse. Comment out the above catch, put in a finally{}, > and Eclipse will tell you what exceptions you need to catch. > > By the way, if you want to be really sure you're catching > everything, even runtime exceptions such as NullPointerException, > use Throwable instead of Exception in your above code.... > > Mike
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|