Hi,
I have a for loop. Inside for loop I have Try Catch. In the catch block - I included a break. If an exception happens I intend to break out of for loop. Is this the right place to break?
Thanks for your input.
Hi,
I have a for loop. Inside for loop I have Try Catch. In the catch block - I included a break. If an exception happens I intend to break out of for loop. Is this the right place to break?
Thanks for your input.
Hi @A_Learner
If your intention is to break out of the for loop immediately when an exception occurs, then adding a break
statement in the catch block is the correct approach. This will cause the for loop to terminate early and continue execution after the loop.
However, if you want to continue executing the for loop and handle the exception outside of the loop, then you should not include the break
statement in the catch block.
Hope this helps,
Best Regards.
Thanks a lot!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.