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