1 // exception.as - MTASC testcase for try/catch
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Original author: Asger Ottar Alstrup <asger@area9.dk>
26 // This movie tests exceptions
34 note
("Test constructor called");
37 function addOneOnFinal
(o
)
48 function throwAndCatchAddingOne
(o
)
62 function throwFromCatchAddingOne
(o
)
70 note
("Catch inside, throwing again (not expected to survive after finally)!");
71 throw e
; // double throw not supported ?
79 function throwNested
(o
)
84 note
("Catch inside, throwing again!");
89 function returnInTryAndCatch
(o
)
93 note
("After return in try");
97 note
("Catch after return in try");
103 function returnInTryCatchAndFinally
(o
)
107 note
("After return in try");
111 note
("Catch after return in try");
116 note
("Finally after returns in try and catch");
122 function tryCatchAndFinally
(o
)
129 o
.sequence
+= "catch";
133 o
.sequence
+= "finally";
138 function returnInCatchAndFinally
(o
)
142 note
("After throw in try");
146 note
("Catch after throw in try");
151 note
("Finally after returns in catch");
167 check_equals
(typeof(res
), 'number');
168 check_equals
(res
, 1);
180 check_equals
(typeof(res
), 'string');
181 check_equals
(res
, 'thrown_finally');
192 check_equals
(typeof(res
), 'number');
193 check_equals
(res
, 3);
195 var o
= new Object();
197 var ret
= addOneOnFinal
(o
);
198 check_equals
(ret
, 'finally');
199 check_equals
(o
.num
, 2);
201 ret
= throwAndCatchAddingOne
(o
);
202 check_equals
(ret
, 'catch');
203 check_equals
(o
.num
, 3);
206 ret
= throwAndCatchAddingOne
(o
);
208 ret
= 'catch_outside';
210 check_equals
(ret
, 'catch');
211 check_equals
(o
.num
, 4);
214 ret
= throwFromCatchAddingOne
(o
);
216 note
("Catch outside");
220 check_equals
(ret
, 'finally');
221 check_equals
(o
.num
, 5);
225 ret
= returnInTryAndCatch
(o
);
227 check_equals
(ret
, "try");
228 check_equals
(o
.num
, 5);
230 ret
= returnInTryCatchAndFinally
(o
);
231 check_equals
(ret
, "finally");
232 check_equals
(o
.num
, 6);
235 tryCatchAndFinally
(o
);
236 check_equals
(o
.sequence
, "tryfinally");
237 check_equals
(o
.num
, 8);
239 ret
= returnInCatchAndFinally
(o
);
240 check_equals
(o
.num
, 9);
241 check_equals
(ret
, "finally");
246 note
("Catch outside");
249 check_equals
(o
.num
, 'throw');
252 static function main
(mc
)
255 var myTest
= new Test
;