|
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 "for-in" statement |
|
6 * |
|
7 * @path ch12/12.14/S12.14_A12_T4.js |
|
8 * @description Try statement inside loop, where combinate using break and continue |
|
9 */ |
|
10 |
|
11 var x; |
|
12 var mycars = new Array(); |
|
13 mycars[0] = "Saab"; |
|
14 mycars[1] = "Volvo"; |
|
15 mycars[2] = "BMW"; |
|
16 |
|
17 // CHECK#1 |
|
18 var c1=0,fin=0; |
|
19 for (x in mycars){ |
|
20 try{ |
|
21 c1+=1; |
|
22 break; |
|
23 } |
|
24 catch(er1){} |
|
25 finally{ |
|
26 fin=1; |
|
27 continue; |
|
28 } |
|
29 fin=-1; |
|
30 c1+=2; |
|
31 } |
|
32 if(fin!==1){ |
|
33 $ERROR('#1.1: "finally" block must be evaluated'); |
|
34 } |
|
35 if(c1!==3){ |
|
36 $ERROR('#1.2: "try{break} catch finally{continue}" must work correctly'); |
|
37 } |
|
38 |
|
39 // CHECK#2 |
|
40 var c2=0,fin2=0; |
|
41 for (x in mycars){ |
|
42 try{ |
|
43 throw "ex1"; |
|
44 } |
|
45 catch(er1){ |
|
46 c2+=1; |
|
47 break; |
|
48 } |
|
49 finally{ |
|
50 fin2=1; |
|
51 continue; |
|
52 } |
|
53 c2+=2; |
|
54 fin2=-1; |
|
55 } |
|
56 if(fin2!==1){ |
|
57 $ERROR('#2.1: "finally" block must be evaluated'); |
|
58 } |
|
59 if(c2!==3){ |
|
60 $ERROR('#2.2: "try catch{break} finally{continue}" must work correctly'); |
|
61 } |
|
62 |