Now if there is an exception in the loop, the catch is outside the loop and you cannot get back in.
But if you structure it this way ...
you can have exception every time through the loop and still keep going.
Would one of those match what you're doing?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 30, 2007
Hello Stan, thanks for the reply.
Yes your second example is what I am doing already but if an exception is thrown then I want to stop the loop and not keep running, in my case this would give an infinite loop, so I want to break out.
My question was that would the catch break out of the loop automatically or do I need to code it, Rahul confirmed my suspicions that I do indeed need to use break to stop the loop when an exception is thrown.
Originally posted by Garrett Rowe: Explicit use of the *break* keyword is almost never necessary outside of a switch construct. In fact, many style guidelines explicitly prohibit its use as it can obfuscate code flow.
They often prohibit "continue", for similar reasons.
Avoiding "break" (outside "switch") and "continue" (everywhere) is generally good style. I personally do not agree with total prohibition; occasionally a loop is more readable when coded with "break" or "continue" than without.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.