source: tests/exceptions/conditional.cfa @ 5c473c9

ADTast-experimental
Last change on this file since 5c473c9 was d00d581, checked in by Henry Xue <y58xue@…>, 3 years ago

Update exception tests to use new syntax

  • Property mode set to 100644
File size: 817 bytes
Line 
1// Conditional Catch Test
2
3// I may fold this back into terminate.cfa and resume.cfa once setting
4// up the non-trivial exception is reasonable to do.
5
6exception num_error {
7        int num;
8};
9
10vtable(num_error) num_error_vt;
11
12void caught_num_error(int expect, num_error * actual) {
13        printf("Caught num_error: expected=%d actual=%d.\n", expect, actual->num);
14}
15
16int main(int argc, char * argv[]) {
17        num_error exc = {&num_error_vt, 2};
18
19        try {
20                throw exc;
21        } catch (num_error * error ; 3 == error->num ) {
22                caught_num_error(3, error);
23        } catch (num_error * error ; 2 == error->num ) {
24                caught_num_error(2, error);
25        }
26
27        try {
28                throwResume exc;
29        } catchResume (num_error * error ; 3 == error->num ) {
30                caught_num_error(3, error);
31        } catchResume (num_error * error ; 2 == error->num ) {
32                caught_num_error(2, error);
33        }
34}
Note: See TracBrowser for help on using the repository browser.