|
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 * Using "try" with "catch" or "finally" statement within/without a "while" statement |
|
6 * |
|
7 * @path ch12/12.14/S12.14_A10_T2.js |
|
8 * @description Try statement inside loop, where use continue loop |
|
9 */ |
|
10 |
|
11 // CHECK#1 |
|
12 var c1=0,fin=0; |
|
13 while(c1<2){ |
|
14 try{ |
|
15 c1+=1; |
|
16 continue; |
|
17 } |
|
18 catch(er1){} |
|
19 finally{ |
|
20 fin=1; |
|
21 } |
|
22 fin=-1; |
|
23 }; |
|
24 if(fin!==1){ |
|
25 $ERROR('#1: "finally" block must be evaluated at "try{continue} catch finally" construction'); |
|
26 } |
|
27 |
|
28 // CHECK#2 |
|
29 var c2=0,fin2=0; |
|
30 while(c2<2){ |
|
31 try{ |
|
32 throw "ex1"; |
|
33 } |
|
34 catch(er1){ |
|
35 c2+=1; |
|
36 continue; |
|
37 } |
|
38 finally{ |
|
39 fin2=1; |
|
40 } |
|
41 fin2=-1; |
|
42 } |
|
43 if(fin2!==1){ |
|
44 $ERROR('#2: "finally" block must be evaluated at "try catch{continue} finally" construction'); |
|
45 } |
|
46 |
|
47 // CHECK#3 |
|
48 var c3=0,fin3=0; |
|
49 while(c3<2){ |
|
50 try{ |
|
51 throw "ex1"; |
|
52 } |
|
53 catch(er1){ |
|
54 c3+=1; |
|
55 } |
|
56 finally{ |
|
57 fin3=1; |
|
58 continue; |
|
59 } |
|
60 fin3=0; |
|
61 } |
|
62 if(fin3!==1){ |
|
63 $ERROR('#3: "finally" block must be evaluated at "try catch finally{continue}" construction'); |
|
64 } |
|
65 |
|
66 // CHECK#4 |
|
67 var c4=0,fin4=0; |
|
68 while(c4<2){ |
|
69 try{ |
|
70 c4+=1; |
|
71 continue; |
|
72 } |
|
73 finally{ |
|
74 fin4=1; |
|
75 } |
|
76 fin4=-1; |
|
77 }; |
|
78 if(fin4!==1){ |
|
79 $ERROR('#4: "finally" block must be evaluated at "try{continue} finally" construction'); |
|
80 } |
|
81 |
|
82 // CHECK#5 |
|
83 var c5=0; |
|
84 while(c5<2){ |
|
85 try{ |
|
86 throw "ex1"; |
|
87 } |
|
88 catch(er1){ |
|
89 c5+=1; |
|
90 continue; |
|
91 } |
|
92 } |
|
93 if(c5!==2){ |
|
94 $ERROR('#5: "try catch{continue}" must work correctly'); |
|
95 } |
|
96 |
|
97 // CHECK#6 |
|
98 var c6=0,fin6=0; |
|
99 while(c6<2){ |
|
100 try{ |
|
101 c6+=1; |
|
102 throw "ex1" |
|
103 } |
|
104 finally{ |
|
105 fin6=1; |
|
106 continue; |
|
107 } |
|
108 fin6=-1; |
|
109 } |
|
110 if(fin6!==1){ |
|
111 $ERROR('#6.1: "finally" block must be evaluated'); |
|
112 } |
|
113 if(c6!==2){ |
|
114 $ERROR('#6.2: "try finally{continue}" must work correctly'); |
|
115 } |
|
116 |