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

StackOverflow https://stackoverflow.com/questions/11113948

  •  15-06-2021
  •  | 
  •  

문제

This 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 work as expected. I.e. the break seems not to work. Can anyone explain why this is?

도움이 되었습니까?

해결책

I'm gonna say it's a BeanShell bug. Not for the reasons outlined below (those apply only to Java on the Mac), but because if you put the same code in a main method in a "classic" Java application it does not behave in the same way. That is, the break condition works.

The following applies only to the latest version of Java on the Mac.

I think it's a BeanShell bug. When I try changing the if to the following BeanShell hangs up:

if(i == 2) {
    print("trying to break");
    break;
}

I forced-closed it and restarted it with the command line. I see the following errors:

$ java -jar bsh-2.0b4.jar 
java[1119] <Error>: CGContextGetCTM: invalid context 0x0
java[1119] <Error>: CGContextSetBaseCTM: invalid context 0x0
java[1119] <Error>: CGContextGetCTM: invalid context 0x0
java[1119] <Error>: CGContextSetBaseCTM: invalid context 0x0
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top