f1、f2、f3の3つの方法があります。f3からf1に戻りたい。
仮定:
最初にf1はf2を呼び出します
f2はf3を呼び出します。
try catchブロックは、3つの機能すべてで使用する必要があります。
この場合、f3で例外が発生した場合、f1に戻ることができるはずです。
ありがとう。
試す..
void f1(){
try{
f2();
}catch(Exception er){}
system.out.println("Exception...");
}
void f2() throws Exception{
f3();
}
void f3() throws Exception{
//on some condition
throw new Exception("something failed");
}
catch(Exception e) {
return;
}
f2で例外をキャッチし、returnを追加して、f1に移動することができます。または、f2で例外をキャッチせず(f2にスローを追加するだけ)、f1に伝播させます。
試す
public void f1(){
f2();
// f3 failed. other code here
}
public void f2(){
try {
f3();
} catch (Exception e){
// Log your exception here
}
return;
}
public void f3(){
throw new Exception("Error:");
}
このようなものを確認してください
void f1() throws Exception {
try {
f2();
} catch (Exception e) {
throw new Exception("Exception Ocuured");
}
}
void f2() throws Exception {
try {
f3();
} catch (Exception e) {
throw new Exception("Exception Ocuured");
}
}
void f3() throws Exception {
try {
// Do Some work here
} catch (Exception e) {
f1();
}
}