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