[21b0a23] | 1 | // Testing polymophic exception types.
|
---|
| 2 |
|
---|
| 3 | #include <exception.hfa>
|
---|
| 4 |
|
---|
[ecfd758] | 5 | EHM_FORALL_EXCEPTION(proxy, (T&), (T))();
|
---|
[21b0a23] | 6 |
|
---|
[ecfd758] | 7 | EHM_FORALL_VIRTUAL_TABLE(proxy, (int), proxy_int);
|
---|
| 8 | EHM_FORALL_VIRTUAL_TABLE(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) *) {
|
---|
| 17 | printf("terminate catch\n");
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | try {
|
---|
[ecfd758] | 21 | throwResume a_char;
|
---|
[21b0a23] | 22 | } catchResume (proxy(char) *) {
|
---|
| 23 | printf("resume catch\n");
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | try {
|
---|
[ecfd758] | 27 | throw a_char;
|
---|
[21b0a23] | 28 | } catch (proxy(int) *) {
|
---|
| 29 | printf("caught proxy(int)\n");
|
---|
| 30 | } catch (proxy(char) *) {
|
---|
| 31 | printf("caught proxy(char)\n");
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[ecfd758] | 35 | EHM_FORALL_EXCEPTION(cell, (T), (T))(
|
---|
[21b0a23] | 36 | T data;
|
---|
| 37 | );
|
---|
| 38 |
|
---|
[ecfd758] | 39 | EHM_FORALL_VIRTUAL_TABLE(cell, (int), int_cell);
|
---|
| 40 | EHM_FORALL_VIRTUAL_TABLE(cell, (char), char_cell);
|
---|
| 41 | EHM_FORALL_VIRTUAL_TABLE(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) {
|
---|
| 48 | printf("%d\n", error->data);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | try {
|
---|
[ecfd758] | 52 | cell(bool) ball = {&bool_cell, false};
|
---|
[21b0a23] | 53 | throwResume ball;
|
---|
| 54 | printf("%i\n", ball.data);
|
---|
| 55 | } catchResume (cell(bool) * error) {
|
---|
| 56 | printf("%i\n", error->data);
|
---|
| 57 | error->data = true;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | int main(int argc, char * argv[]) {
|
---|
| 62 | proxy_test();
|
---|
| 63 | printf("\n");
|
---|
| 64 | cell_test();
|
---|
| 65 | }
|
---|