メソッドが必要です。methodC1()で例外があっても、C2も実行されます。ここでは、methodC1()とmethodC2()という2つのメソッドしか追加していません。多くの方法があるとしましょう。その場合にも、解決策は適用可能でなければならない。すべての行終了後のハンドル例外
abstract class A {
abstract String methodC1() throws ExceptionE;
abstract String methodC2() throws ExceptionE;
protected String methodA() throws ExceptionE2 {
try {
methodC1();
methodC2();
} catch (ExceptionE e) {
throw new ExceptionE2();
}
}
}
class C extends A {
String methodC1() throws ExceptionE {
// do something
}
String methodC2() throws ExceptionE {
// do something
}
}
'methodC2'が' methodC1'とは異なる例外を投げるとどうなりますか? – Azodious
最終的にブロックに入れてください。 – Januson
各メソッドの実装でtry catchを使用し、そのメソッドのみを処理するか、メソッドを呼び出すときに各メソッドに対してtry catchを使用します –