Ile instrukcji w instrukcji try / catch?
Czy powinienem umieścić wiele instrukcji w próbie, a następnie przechwycić wszystkie możliwe wyjątki, czy powinienem umieścić tylko jedną instrukcję w instrukcji try?
Przykład:
try {
MaybeThrowIOException();
MaybeThrowFooBarException();
return true;
} catch (IOException e) {
// ...
} catch (FooBarException e) {
// ...
}
Lub
try {
MaybeThrowIOException();
} catch (IOException e) {
// ...
}
try {
MaybeThrowFooBarException();
} catch (FooBarException e) {
// ...
}
return true;