michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Using "try" with "catch" or "finally" statement with a "return" statement michael@0: * michael@0: * @path ch12/12.14/S12.14_A13_T2.js michael@0: * @description Using try/finally syntax construction michael@0: */ michael@0: michael@0: // CHECK#1 michael@0: var c1=0; michael@0: function myFunction1(){ michael@0: try{ michael@0: return 1; michael@0: }finally{ michael@0: c1=1; michael@0: } michael@0: return 2; michael@0: } michael@0: var x1=myFunction1(); michael@0: if(x1!==1){ michael@0: $ERROR('#1.1: x1===1. Actual: x1==='+x1); michael@0: } michael@0: if (c1!==1){ michael@0: $ERROR('#1.2: "finally" block must be evaluated'); michael@0: } michael@0: michael@0: // CHECK#2 michael@0: var c2=0; michael@0: function myFunction2(){ michael@0: try{ michael@0: throw "exc"; michael@0: return 1; michael@0: }finally{ michael@0: c2=1; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x2=myFunction2(); michael@0: $ERROR('#2.1: Throwing exception inside function lead to throwing exception outside this function'); michael@0: } michael@0: catch(e){ michael@0: if (c2!==1){ michael@0: $ERROR('#2.2: "finally" block must be evaluated'); michael@0: } michael@0: } michael@0: michael@0: // CHECK#3 michael@0: var c3=0; michael@0: function myFunction3(){ michael@0: try{ michael@0: return someValue; michael@0: }finally{ michael@0: c3=1; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x3=myFunction3(); michael@0: $ERROR('#3.1: Throwing exception inside function lead to throwing exception outside this function'); michael@0: } michael@0: catch(e){ michael@0: if (c3!==1){ michael@0: $ERROR('#3.2: "finally" block must be evaluated'); michael@0: } michael@0: } michael@0: michael@0: // CHECK#4 michael@0: var c4=0; michael@0: function myFunction4(){ michael@0: try{ michael@0: return 1; michael@0: }finally{ michael@0: c4=1; michael@0: throw "exc"; michael@0: return 0; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x4=myFunction4(); michael@0: $ERROR('#4.2: Throwing exception inside function lead to throwing exception outside this function'); michael@0: } michael@0: catch(e){ michael@0: if (c4!==1){ michael@0: $ERROR('#4.3: "finally" block must be evaluated'); michael@0: } michael@0: } michael@0: michael@0: // CHECK#5 michael@0: var c5=0; michael@0: function myFunction5(){ michael@0: try{ michael@0: return 1; michael@0: }finally{ michael@0: c5=1; michael@0: return someValue; michael@0: return 0; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x5=myFunction5(); michael@0: $ERROR('#5.2: Throwing exception inside function lead to throwing exception outside this function'); michael@0: } michael@0: catch(e){ michael@0: if (c5!==1){ michael@0: $ERROR('#5.3: "finally" block must be evaluated'); michael@0: } michael@0: } michael@0: michael@0: // CHECK#6 michael@0: var c6=0; michael@0: function myFunction6(){ michael@0: try{ michael@0: throw "ex1"; michael@0: return 1; michael@0: }finally{ michael@0: c6=1; michael@0: throw "ex2"; michael@0: return 2; michael@0: } michael@0: return 3; michael@0: } michael@0: try{ michael@0: var x6=myFunction6(); michael@0: $ERROR('#6.1: Throwing exception inside function lead to throwing exception outside this function'); michael@0: } michael@0: catch(e){ michael@0: if(e==="ex1"){ michael@0: $ERROR('#6.2: Exception !=="ex1". Actual: catch previous exception'); michael@0: } michael@0: if(e!=="ex2"){ michael@0: $ERROR('#6.3: Exception !=="ex1". Actual: '+e); michael@0: } michael@0: if (c6!==1){ michael@0: $ERROR('#6.4: "finally" block must be evaluated'); michael@0: } michael@0: } michael@0: michael@0: // CHECK#7 michael@0: var c7=0; michael@0: function myFunction7(){ michael@0: try{ michael@0: return 1; michael@0: }finally{ michael@0: c7=1; michael@0: return 2; michael@0: } michael@0: return 3; michael@0: } michael@0: var x7=myFunction7(); michael@0: if(x7!==2){ michael@0: $ERROR('#7.1: "catch" block must be evaluated'); michael@0: } michael@0: if (c7!==1){ michael@0: $ERROR('#7.2: "finally" block must be evaluated'); michael@0: } michael@0: michael@0: // CHECK#8 michael@0: var c8=0; michael@0: function myFunction8(){ michael@0: try{ michael@0: throw "ex1"; michael@0: }finally{ michael@0: c8=1; michael@0: return 2; michael@0: } michael@0: return 3; michael@0: } michael@0: try{ michael@0: var x8=myFunction8(); michael@0: } michael@0: catch(ex1){ michael@0: c8=10; michael@0: } michael@0: if (c8!==1){ michael@0: $ERROR('#8: "finally" block must be evaluated'); michael@0: } michael@0: