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_T3.js michael@0: * @description Using try/catch/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: }catch(err){ michael@0: $ERROR('#1.1: "return 1" inside function does not lead to throwing exception'); michael@0: return 0; 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.3: x1===1. Actual: x1==='+x1); michael@0: } michael@0: if (c1!==1){ michael@0: $ERROR('#1.4: "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: }catch(err){ michael@0: return 0; michael@0: }finally{ michael@0: c2=1; michael@0: } michael@0: return 2; michael@0: } michael@0: var x2=myFunction2(); michael@0: if (c2!==1){ michael@0: $ERROR('#2.1: "finally" block must be evaluated'); michael@0: } michael@0: if (x2!==0){ michael@0: $ERROR('#2.2: x2===0. Actual: x2==='+x2); 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: }catch(err){ michael@0: return 1; michael@0: }finally{ michael@0: c3=1; michael@0: } michael@0: return 2; michael@0: } michael@0: var x3=myFunction3(); michael@0: if (c3!==1){ michael@0: $ERROR('#3.1: "finally" block must be evaluated'); michael@0: } michael@0: if (x3!==1){ michael@0: $ERROR('#3.2: x3===1. Actual: x3==='+x3); michael@0: } michael@0: michael@0: // CHECK#4 michael@0: var c4=0; michael@0: function myFunction4(){ michael@0: try{ michael@0: throw "ex1"; michael@0: return 1; michael@0: }catch(err){ michael@0: throw "ex2" michael@0: return 0; michael@0: }finally{ michael@0: c4=1; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x4=myFunction4(); michael@0: $ERROR('#4.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('#4.2: Exception !== "ex1". Actual: catch previous exception'); michael@0: } michael@0: if(e!=="ex2"){ michael@0: $ERROR('#4.3: Exception === "ex2". Actual: Exception ==='+ e ); michael@0: } michael@0: if (c4!==1){ michael@0: $ERROR('#4.4: "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: throw "ex1"; michael@0: return 1; michael@0: }catch(err){ michael@0: return 0; michael@0: }finally{ michael@0: c5=1; michael@0: throw "ex2"; michael@0: } michael@0: return 2; michael@0: } michael@0: try{ michael@0: var x5=myFunction5(); michael@0: $ERROR('#5.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('#5.2: Exception !== "ex1". Actual: catch previous exception'); michael@0: } michael@0: if(e!=="ex2"){ michael@0: $ERROR('#5.3: Exception === "ex2". Actual: Exception ==='+ e ); michael@0: } michael@0: if (c5!==1){ michael@0: $ERROR('#5.4: "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: }catch(err){ michael@0: throw "ex2"; michael@0: return 0; michael@0: }finally{ michael@0: c6=1; michael@0: throw "ex3"; michael@0: } michael@0: return 2; 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 !== "ex2". Actual: catch previous exception'); michael@0: } michael@0: if(e!=="ex3"){ michael@0: $ERROR('#6.4: Exception === "ex3". Actual: Exception ==='+ e ); michael@0: } michael@0: if(c6!==1) $ERROR('#6.5: "finally" block must be evaluated'); michael@0: } michael@0: michael@0: // CHECK#7 michael@0: var c7=0; michael@0: function myFunction7(){ michael@0: try{ michael@0: throw "ex1"; michael@0: return 1; michael@0: }catch(err){ michael@0: throw "ex2"; michael@0: return 0; michael@0: }finally{ michael@0: c7=1; michael@0: return 2; michael@0: } michael@0: return 3; michael@0: } michael@0: try{ michael@0: var x7=myFunction7(); michael@0: if(x7!==2) $ERROR('#7.1: x7===2. Actual: x7==='+x7); michael@0: } michael@0: catch(e){} michael@0: if(c7!==1) $ERROR('#7.2: "finally" block must be evaluated'); michael@0: