Jax Logan
asked on
How do I know which exceptions to catch (java)?
Experts,
I'm new to Java so bear with me.
I'm trying to figure out how I know which exceptions to catch. I read that I should catch all exceptions.
Do I need to read the Java documentation for every method I use and find out which exceptions it might catch?
Do I need to enclose all methods that throws an exception in to a separate try/catch block. Seems like a lot of work or is there an easier way...?
Thanks!
I'm new to Java so bear with me.
I'm trying to figure out how I know which exceptions to catch. I read that I should catch all exceptions.
Do I need to read the Java documentation for every method I use and find out which exceptions it might catch?
Do I need to enclose all methods that throws an exception in to a separate try/catch block. Seems like a lot of work or is there an easier way...?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> Do I need to enclose all methods that throws an exception in to a separate try/catch block. Seems like a lot of work or is there an easier way...?
If you catch the parent of all checked exceptions "java.lang.Exception"
all thrown exceptions will be caught in that catch handler.
If you catch the parent of all checked exceptions "java.lang.Exception"
all thrown exceptions will be caught in that catch handler.
ASKER
So for the checked exceptions, I need to look up every method in the documentation and find out which exception they might throw?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
:)
{
e.getMessage();
}