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 with a "return" statement
6 *
7 * @path ch12/12.14/S12.14_A13_T2.js
8 * @description Using try/finally syntax construction
9 */
11 // CHECK#1
12 var c1=0;
13 function myFunction1(){
14 try{
15 return 1;
16 }finally{
17 c1=1;
18 }
19 return 2;
20 }
21 var x1=myFunction1();
22 if(x1!==1){
23 $ERROR('#1.1: x1===1. Actual: x1==='+x1);
24 }
25 if (c1!==1){
26 $ERROR('#1.2: "finally" block must be evaluated');
27 }
29 // CHECK#2
30 var c2=0;
31 function myFunction2(){
32 try{
33 throw "exc";
34 return 1;
35 }finally{
36 c2=1;
37 }
38 return 2;
39 }
40 try{
41 var x2=myFunction2();
42 $ERROR('#2.1: Throwing exception inside function lead to throwing exception outside this function');
43 }
44 catch(e){
45 if (c2!==1){
46 $ERROR('#2.2: "finally" block must be evaluated');
47 }
48 }
50 // CHECK#3
51 var c3=0;
52 function myFunction3(){
53 try{
54 return someValue;
55 }finally{
56 c3=1;
57 }
58 return 2;
59 }
60 try{
61 var x3=myFunction3();
62 $ERROR('#3.1: Throwing exception inside function lead to throwing exception outside this function');
63 }
64 catch(e){
65 if (c3!==1){
66 $ERROR('#3.2: "finally" block must be evaluated');
67 }
68 }
70 // CHECK#4
71 var c4=0;
72 function myFunction4(){
73 try{
74 return 1;
75 }finally{
76 c4=1;
77 throw "exc";
78 return 0;
79 }
80 return 2;
81 }
82 try{
83 var x4=myFunction4();
84 $ERROR('#4.2: Throwing exception inside function lead to throwing exception outside this function');
85 }
86 catch(e){
87 if (c4!==1){
88 $ERROR('#4.3: "finally" block must be evaluated');
89 }
90 }
92 // CHECK#5
93 var c5=0;
94 function myFunction5(){
95 try{
96 return 1;
97 }finally{
98 c5=1;
99 return someValue;
100 return 0;
101 }
102 return 2;
103 }
104 try{
105 var x5=myFunction5();
106 $ERROR('#5.2: Throwing exception inside function lead to throwing exception outside this function');
107 }
108 catch(e){
109 if (c5!==1){
110 $ERROR('#5.3: "finally" block must be evaluated');
111 }
112 }
114 // CHECK#6
115 var c6=0;
116 function myFunction6(){
117 try{
118 throw "ex1";
119 return 1;
120 }finally{
121 c6=1;
122 throw "ex2";
123 return 2;
124 }
125 return 3;
126 }
127 try{
128 var x6=myFunction6();
129 $ERROR('#6.1: Throwing exception inside function lead to throwing exception outside this function');
130 }
131 catch(e){
132 if(e==="ex1"){
133 $ERROR('#6.2: Exception !=="ex1". Actual: catch previous exception');
134 }
135 if(e!=="ex2"){
136 $ERROR('#6.3: Exception !=="ex1". Actual: '+e);
137 }
138 if (c6!==1){
139 $ERROR('#6.4: "finally" block must be evaluated');
140 }
141 }
143 // CHECK#7
144 var c7=0;
145 function myFunction7(){
146 try{
147 return 1;
148 }finally{
149 c7=1;
150 return 2;
151 }
152 return 3;
153 }
154 var x7=myFunction7();
155 if(x7!==2){
156 $ERROR('#7.1: "catch" block must be evaluated');
157 }
158 if (c7!==1){
159 $ERROR('#7.2: "finally" block must be evaluated');
160 }
162 // CHECK#8
163 var c8=0;
164 function myFunction8(){
165 try{
166 throw "ex1";
167 }finally{
168 c8=1;
169 return 2;
170 }
171 return 3;
172 }
173 try{
174 var x8=myFunction8();
175 }
176 catch(ex1){
177 c8=10;
178 }
179 if (c8!==1){
180 $ERROR('#8: "finally" block must be evaluated');
181 }