source:
tests/exceptions/polymorphic.cfa
@
09bdf2d
Last change on this file since 09bdf2d was 3bf9d10, checked in by , 17 months ago | |
---|---|
|
|
File size: 1.1 KB |
Rev | Line | |
---|---|---|
[21b0a23] | 1 | // Testing polymophic exception types. |
2 | ||
[3bf9d10] | 3 | #include <fstream.hfa> |
4 | ||
[d00d581] | 5 | forall(T &) exception proxy {}; |
[21b0a23] | 6 | |
[d00d581] | 7 | vtable(proxy(int)) proxy_int; |
8 | vtable(proxy(char)) proxy_char; | |
[21b0a23] | 9 | |
[8e2cb4a] | 10 | void proxy_test(void) { |
[ecfd758] | 11 | proxy(int) an_int = {&proxy_int}; |
12 | proxy(char) a_char = {&proxy_char}; | |
13 | ||
[21b0a23] | 14 | try { |
[ecfd758] | 15 | throw an_int; |
[21b0a23] | 16 | } catch (proxy(int) *) { |
[3bf9d10] | 17 | sout | "terminate catch"; |
[21b0a23] | 18 | } |
19 | ||
20 | try { | |
[ecfd758] | 21 | throwResume a_char; |
[21b0a23] | 22 | } catchResume (proxy(char) *) { |
[3bf9d10] | 23 | sout | "resume catch"; |
[21b0a23] | 24 | } |
25 | ||
26 | try { | |
[ecfd758] | 27 | throw a_char; |
[21b0a23] | 28 | } catch (proxy(int) *) { |
[3bf9d10] | 29 | sout | "caught proxy(int)"; |
[21b0a23] | 30 | } catch (proxy(char) *) { |
[3bf9d10] | 31 | sout | "caught proxy(char)"; |
[21b0a23] | 32 | } |
33 | } | |
34 | ||
[d00d581] | 35 | forall(T) exception cell { |
[21b0a23] | 36 | T data; |
[d00d581] | 37 | }; |
[21b0a23] | 38 | |
[d00d581] | 39 | vtable(cell(int)) int_cell; |
40 | vtable(cell(char)) char_cell; | |
41 | vtable(cell(bool)) bool_cell; | |
[21b0a23] | 42 | |
43 | void cell_test(void) { | |
44 | try { | |
[ecfd758] | 45 | cell(int) except = {&int_cell, -7}; |
[21b0a23] | 46 | throw except; |
47 | } catch (cell(int) * error) { | |
[3bf9d10] | 48 | sout | error->data; |
[21b0a23] | 49 | } |
50 | ||
51 | try { | |
[ecfd758] | 52 | cell(bool) ball = {&bool_cell, false}; |
[21b0a23] | 53 | throwResume ball; |
[3bf9d10] | 54 | sout | ball.data; |
[21b0a23] | 55 | } catchResume (cell(bool) * error) { |
[3bf9d10] | 56 | sout | error->data; |
[21b0a23] | 57 | error->data = true; |
58 | } | |
59 | } | |
60 | ||
61 | int main(int argc, char * argv[]) { | |
62 | proxy_test(); | |
[3bf9d10] | 63 | sout | nl; |
[21b0a23] | 64 | cell_test(); |
65 | } |
Note: See TracBrowser
for help on using the repository browser.