Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | // Copyright 2009 the Sputnik authors. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Using "try" with "catch" or "finally" statement with a "return" statement |
michael@0 | 6 | * |
michael@0 | 7 | * @path ch12/12.14/S12.14_A13_T1.js |
michael@0 | 8 | * @description Using try/catch syntax construction |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | // CHECK#1 |
michael@0 | 12 | function myFunction1(){ |
michael@0 | 13 | try{ |
michael@0 | 14 | return 1; |
michael@0 | 15 | } |
michael@0 | 16 | catch(err){ |
michael@0 | 17 | $ERROR('#1.1: "return 1" inside function does not lead to throwing exception'); |
michael@0 | 18 | return 0; |
michael@0 | 19 | } |
michael@0 | 20 | return 2; |
michael@0 | 21 | } |
michael@0 | 22 | var x1=myFunction1(); |
michael@0 | 23 | if(x1!==1){ |
michael@0 | 24 | $ERROR('#1.2: x1===1. Actual: x1==='+x1); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | // CHECK#2 |
michael@0 | 28 | function myFunction2(){ |
michael@0 | 29 | try{ |
michael@0 | 30 | throw "exc"; |
michael@0 | 31 | return 1; |
michael@0 | 32 | }catch(err){ |
michael@0 | 33 | return 2; |
michael@0 | 34 | } |
michael@0 | 35 | return 3; |
michael@0 | 36 | } |
michael@0 | 37 | var x2=myFunction2(); |
michael@0 | 38 | if (x2!==2){ |
michael@0 | 39 | $ERROR('#2: x2===2. Actual: x2==='+x2); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // CHECK#3 |
michael@0 | 43 | function myFunction3(){ |
michael@0 | 44 | try{ |
michael@0 | 45 | return someValue; |
michael@0 | 46 | }catch(err){ |
michael@0 | 47 | return 1; |
michael@0 | 48 | } |
michael@0 | 49 | return 2; |
michael@0 | 50 | } |
michael@0 | 51 | var x3=myFunction3(); |
michael@0 | 52 | if (x3!==1){ |
michael@0 | 53 | $ERROR('#3: x3===1. Actual: x3==='+x3); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // CHECK#4 |
michael@0 | 57 | function myFunction4(){ |
michael@0 | 58 | try{ |
michael@0 | 59 | throw "ex1"; |
michael@0 | 60 | return 1; |
michael@0 | 61 | }catch(err){ |
michael@0 | 62 | throw "ex2" |
michael@0 | 63 | return 0; |
michael@0 | 64 | } |
michael@0 | 65 | return 2; |
michael@0 | 66 | } |
michael@0 | 67 | try{ |
michael@0 | 68 | var x4=myFunction4(); |
michael@0 | 69 | $ERROR('#4.1: Throwing exception inside function lead to throwing exception outside this function'); |
michael@0 | 70 | } |
michael@0 | 71 | catch(e){ |
michael@0 | 72 | if(e==="ex1"){ |
michael@0 | 73 | $ERROR('#4.2: Exception !=="ex1". Actual: catch previous exception'); |
michael@0 | 74 | } |
michael@0 | 75 | if(e!=="ex2"){ |
michael@0 | 76 | $ERROR('#4.3: Exception ==="ex2". Actual: Exception ==='+ e ); |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 |