If I have a try ... catch
block inside a while
loop, and there#s a break
inside the catch
, does program execution leave t
A break
statement always applies to the innermost while
, do
, or switch
, regardless of other intervening statements. However, there is one case where the break
will not cause the loop to exit:
while (!finished) {
try {
doStuff();
} catch (Exception e) {
break;
} finally {
continue;
}
}
Here, the abrupt completion of the finally
is the cause of the abrupt completion of the try
, and the abrupt completion of the catch
is lost.