1 | // Testing polymophic exception types. |
---|
2 | |
---|
3 | #include <exception.hfa> |
---|
4 | |
---|
5 | FORALL_TRIVIAL_EXCEPTION(proxy, (T), (T)); |
---|
6 | FORALL_TRIVIAL_INSTANCE(proxy, (U), (U)) |
---|
7 | |
---|
8 | const char * msg(proxy(int) * this) { return "proxy(int)"; } |
---|
9 | const char * msg(proxy(char) * this) { return "proxy(char)"; } |
---|
10 | POLY_VTABLE_INSTANCE(proxy, int)(msg); |
---|
11 | POLY_VTABLE_INSTANCE(proxy, char)(msg); |
---|
12 | |
---|
13 | void proxy_test(void) { |
---|
14 | try { |
---|
15 | throw (proxy(int)){}; |
---|
16 | } catch (proxy(int) *) { |
---|
17 | printf("terminate catch\n"); |
---|
18 | } |
---|
19 | |
---|
20 | try { |
---|
21 | throwResume (proxy(char)){}; |
---|
22 | } catchResume (proxy(char) *) { |
---|
23 | printf("resume catch\n"); |
---|
24 | } |
---|
25 | |
---|
26 | try { |
---|
27 | throw (proxy(char)){}; |
---|
28 | } catch (proxy(int) *) { |
---|
29 | printf("caught proxy(int)\n"); |
---|
30 | } catch (proxy(char) *) { |
---|
31 | printf("caught proxy(char)\n"); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | FORALL_DATA_EXCEPTION(cell, (T), (T))( |
---|
36 | T data; |
---|
37 | ); |
---|
38 | |
---|
39 | FORALL_DATA_INSTANCE(cell, (T), (T)) |
---|
40 | |
---|
41 | const char * msg(cell(int) * this) { return "cell(int)"; } |
---|
42 | const char * msg(cell(char) * this) { return "cell(char)"; } |
---|
43 | const char * msg(cell(bool) * this) { return "cell(bool)"; } |
---|
44 | POLY_VTABLE_INSTANCE(cell, int)(msg); |
---|
45 | POLY_VTABLE_INSTANCE(cell, char)(msg); |
---|
46 | POLY_VTABLE_INSTANCE(cell, bool)(msg); |
---|
47 | |
---|
48 | void cell_test(void) { |
---|
49 | try { |
---|
50 | cell(int) except; |
---|
51 | except.data = -7; |
---|
52 | throw except; |
---|
53 | } catch (cell(int) * error) { |
---|
54 | printf("%d\n", error->data); |
---|
55 | } |
---|
56 | |
---|
57 | try { |
---|
58 | cell(bool) ball; |
---|
59 | ball.data = false; |
---|
60 | throwResume ball; |
---|
61 | printf("%i\n", ball.data); |
---|
62 | } catchResume (cell(bool) * error) { |
---|
63 | printf("%i\n", error->data); |
---|
64 | error->data = true; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | int main(int argc, char * argv[]) { |
---|
69 | proxy_test(); |
---|
70 | printf("\n"); |
---|
71 | cell_test(); |
---|
72 | } |
---|