I have your standard try/catch statement:
try
{
// Do a bunch of stuff
}
catch ( Exception e )
{
throw e;
}
Is there any way to determine what possible Exceptions could be caught from my code without trying to force my code to fail in order to see what type of Exception e is?
For example, if I did some HTTP calls or maybe some JSON stuff that I want to handle differently, my code might look like this:
try
{
// Do a bunch of stuff
}
catch ( HttpException e )
{
// Do something
throw e;
}
catch ( JSONException e )
{
// Do something else
throw e;
}
catch ( Exception e )
{
throw e;
}
But maybe I’m doing a whole bunch of stuff in my code and I’m not sure (due to lack of Java experience) what the possible Exceptions are that could be caught…
Is there any possible way to use Eclipse to look at a set of code and get a list of every possible type of exception that could be caught?
Well there’s two types of exceptions: checked and unchecked.
You can’t get a list of all unchecked exceptions, because they might not tell you what they are. (They might, if you read the documentation for the libraries you’re using.)
For checked exceptions, you wouldn’t be able to compile the code if you weren’t catching them all. I would simply remove the
Exception eblock and compile with it. Honestly catching every exception is a bad idea unless you’re truly prepared to handle it.