source: tests/exceptions/data-except.cfa @ 046a890

arm-ehjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since 046a890 was 046a890, checked in by Andrew Beach <ajbeach@…>, 19 months ago

That should get default operations working for throws. More tests to come.

  • Property mode set to 100644
File size: 937 bytes
Line 
1// Test exceptions that add data but no functionality.
2
3#include <exception.hfa>
4
5DATA_EXCEPTION(paired)(
6        int first;
7        int second;
8);
9
10void ?{}(paired & this, int first, int second) {
11        VTABLE_INIT(this, paired);
12        this.first = first;
13        this.second = second;
14}
15
16const char * paired_msg(paired * this) {
17        return "paired";
18}
19
20VTABLE_INSTANCE(paired)(paired_msg);
21
22void throwPaired(int first, int second) {
23        paired exc = {first, second};
24}
25
26int main(int argc, char * argv[]) {
27        paired except = {3, 13};
28
29        try {
30                throw except;
31        } catch (paired * exc) {
32                printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
33                ++exc->first;
34        }
35
36        printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
37
38        try {
39                throwResume except;
40        } catchResume (paired * exc) {
41                printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
42                ++exc->first;
43        }
44
45        printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
46}
Note: See TracBrowser for help on using the repository browser.