int someCounter = 0;
boolean finished = false;
while(someCounter < 3 && !finished) {
try {
finished = true;
} catch (some exception) {
someCounter++;
}
}
You can break;in the block try catch, and it will exit the loop in which it is located (and not just the block try catch), but from the point of view of readability, this published code may be better.
finished = true try. . , try exception. , finished = true, , .
, , finished = true; . , someCounter++.
, while while. , someCounter, finished true. , , , , , , , , , break;.