As it is said in The Java Language Specification (http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.15):
“The preceding descriptions say “attempts to transfer control” rather than just “transfers control” because if there are any try
statements within the break target whose try
blocks contain the break
statement, then any finally
clauses of those try
statements are executed, in order, innermost to outermost, before control is transferred to the break target. Abrupt completion of a finally
clause can disrupt the transfer of control initiated by a break
statement.”
Let’s look into next example:
public class Test { private static void test() throws Exception { for (int i = 0; i < 3; i++) { try { throw new Exception("Exception text"); } finally { System.out.println("Finally exception " + i); continue; } } System.out.println("Impossible"); } public static void main(String[] args) throws Exception { test(); System.out.println("Impossible 2"); } }
will produce output:
Finally exception 0
Finally exception 1
Finally exception 2
Impossible
Impossible 2
So, be extremely careful with your breaks!
Looks perfectly straight to me. Of course, I’m also the type of person who allegedly [ahem! allegedly] agree with everything.
LikeLike