1 /* Standalone program to test functionality of exceptions.
5 * Copyright (c) 2004 MX Telecom Ltd. <richardv@mxtelecom.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "exceptions.h"
28 gboolean failed
= FALSE
;
33 volatile unsigned int ex_thrown
, finally_called
;
35 /* check that the right catch, and the finally, are called, on exception */
36 ex_thrown
= finally_called
= 0;
43 CATCH(FragmentBoundsError
) {
44 printf("01: Caught wrong exception: FragmentBoundsError\n");
47 CATCH(ReportedBoundsError
) {
48 printf("01: Caught wrong exception: ReportedBoundsError\n");
52 printf("01: Caught wrong exception: %lu\n", exc
->except_id
.except_code
);
61 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown
);
65 if (finally_called
!= 1) {
66 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called
);
71 /* check that no catch at all is called when there is no exn */
72 ex_thrown
= finally_called
= 0;
76 printf("02: Caught wrong exception: BoundsError\n");
79 CATCH(FragmentBoundsError
) {
80 printf("02: Caught wrong exception: FragmentBoundsError\n");
83 CATCH(ReportedBoundsError
) {
84 printf("02: Caught wrong exception: ReportedBoundsError\n");
88 printf("02: Caught wrong exception: %lu\n", exc
->except_id
.except_code
);
96 if (finally_called
!= 1) {
97 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called
);
102 /* check that finally is called on an uncaught exception */
103 ex_thrown
= finally_called
= 0;
118 if (finally_called
!= 1) {
119 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called
);
123 if (ex_thrown
!= 1) {
124 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown
);
129 /* check that finally is called on an rethrown exception */
130 ex_thrown
= finally_called
= 0;
140 finally_called
+= 10;
152 if (finally_called
!= 11) {
153 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called
);
157 if (ex_thrown
!= 11) {
158 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown
);
163 /* check that finally is called on an exception thrown from a CATCH block */
164 ex_thrown
= finally_called
= 0;
171 printf("05: Looping exception\n");
179 finally_called
+= 10;
191 if (finally_called
!= 11) {
192 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called
);
196 if (ex_thrown
!= 11) {
197 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown
);