Should I put multiple statements in a try and then catch all possible exceptions, or should I put only one statement in the try statement?
Example:
try {
MaybeThrowIOException();
MaybeThrowFooBarException();
return true;
} catch (IOException e) {
// ...
} catch (FooBarException e) {
// ...
}
Or
try {
MaybeThrowIOException();
} catch (IOException e) {
// ...
}
try {
MaybeThrowFooBarException();
} catch (FooBarException e) {
// ...
}
return true;