Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 // Copyright 2009 the Sputnik authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 /**
5 * Using "try" with "catch" or "finally" statement within/without a "with" statement
6 *
7 * @path ch12/12.14/S12.14_A14.js
8 * @description Using try/catch/finally in With and With in try/catch/finally
9 * @noStrict
10 */
12 var myObj = {p1: 'a',
13 p2: 'b',
14 p3: 'c',
15 value: 'myObj_value',
16 valueOf : function(){return 'obj_valueOf';},
17 parseInt : function(){return 'obj_parseInt';},
18 NaN : 'obj_NaN',
19 Infinity : 'obj_Infinity',
20 eval : function(){return 'obj_eval';},
21 parseFloat : function(){return 'obj_parseFloat';},
22 isNaN : function(){return 'obj_isNaN';},
23 isFinite : function(){return 'obj_isFinite';}
24 }
26 // CHECK#1
27 try{
28 with(myObj){
29 throw "ex";
30 }
31 }
32 catch(e){
33 if (e!=="ex") $ERROR('#1: Exception ==="ex". Actual: Exception ==='+ e );
34 }
36 // CHECK#2
37 with(myObj){
38 try{
39 throw p1;
40 }
41 catch(e){
42 if (e!=="a") $ERROR('#2.1: Exception ==="a". Actual: Exception ==='+ e );
43 p1='pass';
44 }
45 }
46 if(myObj.p1!=='pass') $ERROR('#2.2: "throw p1" lead to throwing exception');
48 // CHECK#3
49 with(myObj){
50 try{
51 p1='fail';
52 throw p2;
53 }
54 catch(e){
55 if (e!=="b") $ERROR('#3.1: Exception ==="b". Actual: Exception ==='+ e );
56 p1='pass';
57 }
58 finally{
59 p2='pass';
60 }
61 }
62 if(myObj.p1!=='pass') $ERROR('#3.2: "throw p2" lead to throwing exception');
63 if(myObj.p2!=='pass') $ERROR('#3.3: "finally" block must be evaluated');
65 // CHECK#4
66 myObj.p1='fail';
67 try{
68 with(myObj){
69 try{
70 throw p3;
71 }
72 finally{
73 p1='pass';
74 }
75 }
76 }
77 catch(e){}
78 if(myObj.p1!=='pass') $ERROR('#4: "finally" block must be evaluated');