while (true) {
try {
//create ImportantObject
LoopToGoTo:
for (int i = 0; i < Limit; i++) {
//method in here throws the exception
//ImportantObject is used in here.
}
} catch(Exception e) {
//report error
continue LoopToGoTo;
}
}
trycatchブロック内のループを続行したいと思います。これは可能ですか?
編集:申し訳ありませんが、trycatchをforループ内に移動できなかった理由がわかりませんでした。(編集されたスニペット)forループ内にtry-catchを配置すると、内部の呼び出しは、ImportantObjectにアクセスできなくなります。これは私が立ち往生している場所です。
EDIT2:さて、ラベルを続行せずに、問題を解決しました!私の質問に対する答えは単純な「いいえ」だと思います。悪い習慣はいたるところにあるかもしれませんが、私の割り当ては2時間で期限が切れます。私は何を言うことができます:D
//ImportantClass ImportantObject = null;
while (!ranOnce) {
try {
//create ImportantObject
ranOnce = true;
} catch(Exception e) {
//report error
continue;
}
}
for (int i = 0; i < Limit; i++) {
try {
//method in here throws the exception
//ImportantObject is used in here.
} catch(Exception e) {
//report error
continue;
}
}