选项 A:
public void method() {
try {
// some operation that throws FirstException
} catch (FirstException ex) {
throw new RuntimeException(ex);
}
try {
// some operation that throws SecondException
} catch (SecondException ex) {
throw new RuntimeException(ex);
}
}
选项 B:
public void method() {
try {
// some operation that throws FirstException
// some operation that throws SecondException
} catch (FirstException ex) {
throw new RuntimeException(ex);
} catch (SecondException ex) {
throw new RuntimeException(ex);
}
}
哪个更好,为什么?