On 2011-11-11, at 9:37 AM, Erick Lavoie wrote:
1 function test() 2 { 3 var a = 1; 4 try { 5 throw "exception"; 6 } catch (e) 7 { 8 print("catch"); 9 return a; 10 } finally 11 { 12 a = 2; 13 print("finally a = " + a); 14 } 15 16 print("end"); 17 }; 18 19 print("test = " + test());
Output:
catch finally a = 2 test = 1
This time, the fun part is that the value of 'a' at 9 is bound before the finally block is executed, although the actual return from the function is done after the execution of the finally block.
I am not extremely familiar with exception systems so this might be standard behavior. It means however that the meaning of return depends on the presence or absence of a finally block.
This seems like standard behaviour to me. It should be impossible to circumvent a finally block from within the try. It works exactly the same way in Java, for example.
Bruno