1 /* Standalone program to test functionality of exceptions.
3 * Copyright (c) 2004 MX Telecom Ltd. <richardv@mxtelecom.com>
5 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "exceptions.h"
18 finally_called_uncaught_exception(volatile unsigned int* called
)
30 finally_called_rethrown_exception(volatile unsigned int* thrown
, volatile unsigned int* called
)
46 finally_called_exception_from_catch(volatile unsigned int* thrown
, volatile unsigned int* called
)
53 printf("05: Looping exception\n");
69 volatile unsigned int ex_thrown
, finally_called
;
71 /* check that the right catch, and the finally, are called, on exception */
72 ex_thrown
= finally_called
= 0;
79 CATCH(FragmentBoundsError
) {
80 printf("01: Caught wrong exception: FragmentBoundsError\n");
83 CATCH(ReportedBoundsError
) {
84 printf("01: Caught wrong exception: ReportedBoundsError\n");
88 printf("01: Caught wrong exception: %lu\n", exc
->except_id
.except_code
);
97 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown
);
101 if (finally_called
!= 1) {
102 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called
);
107 /* check that no catch at all is called when there is no exn */
108 ex_thrown
= finally_called
= 0;
112 printf("02: Caught wrong exception: BoundsError\n");
115 CATCH(FragmentBoundsError
) {
116 printf("02: Caught wrong exception: FragmentBoundsError\n");
119 CATCH(ReportedBoundsError
) {
120 printf("02: Caught wrong exception: ReportedBoundsError\n");
124 printf("02: Caught wrong exception: %lu\n", exc
->except_id
.except_code
);
132 if (finally_called
!= 1) {
133 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called
);
137 /* check that finally is called on an uncaught exception */
138 ex_thrown
= finally_called
= 0;
140 finally_called_uncaught_exception(&finally_called
);
147 if (finally_called
!= 1) {
148 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called
);
152 if (ex_thrown
!= 1) {
153 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown
);
158 /* check that finally is called on an rethrown exception */
159 ex_thrown
= finally_called
= 0;
161 finally_called_rethrown_exception(&ex_thrown
, &finally_called
);
171 if (finally_called
!= 11) {
172 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called
);
176 if (ex_thrown
!= 11) {
177 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown
);
182 /* check that finally is called on an exception thrown from a CATCH block */
183 ex_thrown
= finally_called
= 0;
185 finally_called_exception_from_catch(&ex_thrown
, &finally_called
);
195 if (finally_called
!= 11) {
196 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called
);
200 if (ex_thrown
!= 11) {
201 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown
);
218 * Editor modelines - https://www.wireshark.org/tools/modelines.html
223 * indent-tabs-mode: nil
226 * vi: set shiftwidth=4 tabstop=8 expandtab:
227 * :indentSize=4:tabSize=8:noTabs=true: