page.tsif-elseブロックの外側にあるコードを実行しないようにするにはどうしたらいいですか?
//all imports are made correctly
export class page{
constructor(){}//used DI correctly.
public someFunction(){
let result: any;
if(x = true){
try{
result = this.serviceClass.doSomething();
}
catch(e){
//do some processing.
}
}
else{
try {
result = this.serviceClass.doAnotherThing();
}
catch(e){
//do some processing.
}
}
console.log(result); //line 1
service2.oneThing(); ///line 2
//other tasks and common functions. //line 3
}
}
Question1:上記のコード断片では、どのように私はライン1、ライン2とライン3の実行を停止しますか?いずれかのtryブロックが例外をキャッチします。
質問2:if-elseステートメントのいずれかで1つのtry-catchブロックしか使用できないのですか?ifまたはelseブロックで例外が検出された場合、1つのtry-catchブロックのみがすべてを処理します。共通コードは行1の行2を実行しません。&行3
私は、ロジックコードが関数内にラップされているものとします。 –
ohhはい、申し訳ありません.. – Aditya