Help save net neutrality! Learn more.
Close

#239 An exception in break label

open
nobody
None
5
2005-08-10
2005-08-10
Nigel
No

> cat t94.java
class t94 {
public static void main(String[] args) {
boolean t = true;
first :
{
second :
{
third :
{
System.out.println("Who is best?");
if (t)
break second;
}
System.out.println("BeanShell perhaps");
}
System.out.println("Nigel of course");
}
}
}

Process cat exited with code 0

As expected Java knows the truth

> javac t94.java
Process javac exited with code 0
> java t94
Who is best?
Nigel of course
Process java exited with code 0

BeanShell just can not bring itself to print it.

> java -classpath /opt/bsh-2.0b5.jar bsh.Interpreter
t94.java
Who is best?
Class: class t94 main method threw exception:'continue'
or 'break' in method body : at Line: 12 : in file: t94.java :
break second ;

Called from method: main : at Line: -1 : in file: <Called
from Java Code> : <Compiled Java Code>
Process java exited with code 0

Discussion


Log in to post a comment.