1 /* Standalone program to test functionality of exceptions.
3 * Copyright (c) 2004 MX Telecom Ltd. <richardv@mxtelecom.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "exceptions.h"
26 gboolean failed = FALSE;
31 volatile unsigned int ex_thrown, finally_called;
33 /* check that the right catch, and the finally, are called, on exception */
34 ex_thrown = finally_called = 0;
41 CATCH(FragmentBoundsError) {
42 printf("01: Caught wrong exception: FragmentBoundsError\n");
45 CATCH(ReportedBoundsError) {
46 printf("01: Caught wrong exception: ReportedBoundsError\n");
50 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
59 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
63 if (finally_called != 1) {
64 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
69 /* check that no catch at all is called when there is no exn */
70 ex_thrown = finally_called = 0;
74 printf("02: Caught wrong exception: BoundsError\n");
77 CATCH(FragmentBoundsError) {
78 printf("02: Caught wrong exception: FragmentBoundsError\n");
81 CATCH(ReportedBoundsError) {
82 printf("02: Caught wrong exception: ReportedBoundsError\n");
86 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
94 if (finally_called != 1) {
95 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
100 /* check that finally is called on an uncaught exception */
101 ex_thrown = finally_called = 0;
116 if (finally_called != 1) {
117 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
121 if (ex_thrown != 1) {
122 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
127 /* check that finally is called on an rethrown exception */
128 ex_thrown = finally_called = 0;
138 finally_called += 10;
150 if (finally_called != 11) {
151 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
155 if (ex_thrown != 11) {
156 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
161 /* check that finally is called on an exception thrown from a CATCH block */
162 ex_thrown = finally_called = 0;
169 printf("05: Looping exception\n");
177 finally_called += 10;
189 if (finally_called != 11) {
190 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
194 if (ex_thrown != 11) {
195 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);