Re: Why does break in a for loop not work when finally is involved

Nils Andresen <nils-AVNmLDg75hOg/[email protected]> Fri, 17 Aug 2012 09:59:15 +0200
Newsgroups gmane.comp.java.beanshell.user
Message-ID <CACKUC=7sEgBz3=b1N_eqPUFk6iRuEKkSEiyFfP+Yg=ULkBoHQA@mail.gmail.com>
Hi,
to have this "complete".
This seems to be a bug in beanshell. It's fixed in beanshell2, though.

Best,
Nils

2012/6/21 Nils Andresen <nils-AVNmLDg75hOg/[email protected]>:
> Hi,
> The following code:
> print(" - Start");
> int[] num = new int[] {1,2,3,4,5,6,7,8,9,10};
> for(int i : num)
> {
>     print("--> "+ i);
>     try
>     {
>         Print("    . try");
>         if(i == 2)
>             break;
>     }
>     catch (java.lang.Exception e)
>     {}
>     finally
>     {
>         print("    . finally");
>     }
> }
> print(" - End");
>
> does not break as expected but runs all 10 iterations. If I remove the
> finally block everything works as expected. Can someone tell me why
> this is?
>
> Best,
> Nils
>
> P.S.
> I posted this question at [1] but it seems there are not so many
> beanshell users at stackoverflow...
>
> 1: http://stackoverflow.com/questions/11113948/why-does-break-in-a-for-loop-not-work-when-finally-is-involved-in-beanshell

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/