source:
tests/exceptions/polymorphic.cfa
@
24ebddac
Last change on this file since 24ebddac was d00d581, checked in by , 3 years ago | |
---|---|
|
|
File size: 1.1 KB |
Rev | Line | |
---|---|---|
[21b0a23] | 1 | // Testing polymophic exception types. |
2 | ||
[d00d581] | 3 | forall(T &) exception proxy {}; |
[21b0a23] | 4 | |
[d00d581] | 5 | vtable(proxy(int)) proxy_int; |
6 | vtable(proxy(char)) proxy_char; | |
[21b0a23] | 7 | |
[8e2cb4a] | 8 | void proxy_test(void) { |
[ecfd758] | 9 | proxy(int) an_int = {&proxy_int}; |
10 | proxy(char) a_char = {&proxy_char}; | |
11 | ||
[21b0a23] | 12 | try { |
[ecfd758] | 13 | throw an_int; |
[21b0a23] | 14 | } catch (proxy(int) *) { |
15 | printf("terminate catch\n"); | |
16 | } | |
17 | ||
18 | try { | |
[ecfd758] | 19 | throwResume a_char; |
[21b0a23] | 20 | } catchResume (proxy(char) *) { |
21 | printf("resume catch\n"); | |
22 | } | |
23 | ||
24 | try { | |
[ecfd758] | 25 | throw a_char; |
[21b0a23] | 26 | } catch (proxy(int) *) { |
27 | printf("caught proxy(int)\n"); | |
28 | } catch (proxy(char) *) { | |
29 | printf("caught proxy(char)\n"); | |
30 | } | |
31 | } | |
32 | ||
[d00d581] | 33 | forall(T) exception cell { |
[21b0a23] | 34 | T data; |
[d00d581] | 35 | }; |
[21b0a23] | 36 | |
[d00d581] | 37 | vtable(cell(int)) int_cell; |
38 | vtable(cell(char)) char_cell; | |
39 | vtable(cell(bool)) bool_cell; | |
[21b0a23] | 40 | |
41 | void cell_test(void) { | |
42 | try { | |
[ecfd758] | 43 | cell(int) except = {&int_cell, -7}; |
[21b0a23] | 44 | throw except; |
45 | } catch (cell(int) * error) { | |
46 | printf("%d\n", error->data); | |
47 | } | |
48 | ||
49 | try { | |
[ecfd758] | 50 | cell(bool) ball = {&bool_cell, false}; |
[21b0a23] | 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.