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_T1.js michael@0: * @description Using try/catch syntax construction michael@0: */ michael@0: michael@0: // CHECK#1 michael@0: function myFunction1(){ michael@0: try{ michael@0: return 1; michael@0: } 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: } michael@0: return 2; michael@0: } michael@0: var x1=myFunction1(); michael@0: if(x1!==1){ michael@0: $ERROR('#1.2: x1===1. Actual: x1==='+x1); michael@0: } michael@0: michael@0: // CHECK#2 michael@0: function myFunction2(){ michael@0: try{ michael@0: throw "exc"; michael@0: return 1; michael@0: }catch(err){ michael@0: return 2; michael@0: } michael@0: return 3; michael@0: } michael@0: var x2=myFunction2(); michael@0: if (x2!==2){ michael@0: $ERROR('#2: x2===2. Actual: x2==='+x2); michael@0: } michael@0: michael@0: // CHECK#3 michael@0: function myFunction3(){ michael@0: try{ michael@0: return someValue; michael@0: }catch(err){ michael@0: return 1; michael@0: } michael@0: return 2; michael@0: } michael@0: var x3=myFunction3(); michael@0: if (x3!==1){ michael@0: $ERROR('#3: x3===1. Actual: x3==='+x3); michael@0: } michael@0: michael@0: // CHECK#4 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: } 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: } michael@0: