ADTast-experimentalpthread-emulationqualifiedEnum
Last change
on this file since 8419b76 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:
1.1 KB
|
Line | |
---|
1 | // Testing polymophic exception types. |
---|
2 | |
---|
3 | forall(T &) exception proxy {}; |
---|
4 | |
---|
5 | vtable(proxy(int)) proxy_int; |
---|
6 | vtable(proxy(char)) proxy_char; |
---|
7 | |
---|
8 | void proxy_test(void) { |
---|
9 | proxy(int) an_int = {&proxy_int}; |
---|
10 | proxy(char) a_char = {&proxy_char}; |
---|
11 | |
---|
12 | try { |
---|
13 | throw an_int; |
---|
14 | } catch (proxy(int) *) { |
---|
15 | printf("terminate catch\n"); |
---|
16 | } |
---|
17 | |
---|
18 | try { |
---|
19 | throwResume a_char; |
---|
20 | } catchResume (proxy(char) *) { |
---|
21 | printf("resume catch\n"); |
---|
22 | } |
---|
23 | |
---|
24 | try { |
---|
25 | throw a_char; |
---|
26 | } catch (proxy(int) *) { |
---|
27 | printf("caught proxy(int)\n"); |
---|
28 | } catch (proxy(char) *) { |
---|
29 | printf("caught proxy(char)\n"); |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | forall(T) exception cell { |
---|
34 | T data; |
---|
35 | }; |
---|
36 | |
---|
37 | vtable(cell(int)) int_cell; |
---|
38 | vtable(cell(char)) char_cell; |
---|
39 | vtable(cell(bool)) bool_cell; |
---|
40 | |
---|
41 | void cell_test(void) { |
---|
42 | try { |
---|
43 | cell(int) except = {&int_cell, -7}; |
---|
44 | throw except; |
---|
45 | } catch (cell(int) * error) { |
---|
46 | printf("%d\n", error->data); |
---|
47 | } |
---|
48 | |
---|
49 | try { |
---|
50 | cell(bool) ball = {&bool_cell, false}; |
---|
51 | throwResume ball; |
---|
52 | printf("%i\n", ball.data); |
---|
53 | } catchResume (cell(bool) * error) { |
---|
54 | printf("%i\n", error->data); |
---|
55 | error->data = true; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | int main(int argc, char * argv[]) { |
---|
60 | proxy_test(); |
---|
61 | printf("\n"); |
---|
62 | cell_test(); |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.