source: tests/exceptions/interact.cfa @ ecfd758

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ecfd758 was ecfd758, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1// Testing Interactions Between Termination and Resumption
2
3#include <exception.hfa>
4#include "except-io.hfa"
5
6EHM_EXCEPTION(star)();
7EHM_EXCEPTION(moon)();
8
9EHM_VIRTUAL_TABLE(star, star_vt);
10EHM_VIRTUAL_TABLE(moon, moon_vt);
11
12int main(int argc, char * argv[]) {
13        // Resume falls back to terminate.
14        try {
15                throwResume (star){&star_vt};
16        } catch (star *) {
17                printf("caught as termination\n");
18        }
19        // Variant of the above to check timing.
20        try {
21                loud_region a = "try block with resume throw";
22                throwResume (star){&star_vt};
23        } catch (star *) {
24                printf("caught as termination\n");
25        } catchResume (star *) {
26                printf("intermediate rethrow\n");
27                throwResume;
28        }
29        printf("\n");
30
31        // Resume does not catch terminate.
32        try {
33                try {
34                        throw (star){&star_vt};
35                } catchResume (star *) {
36                        printf("resume catch on terminate\n");
37                }
38        } catchResume (star *) {
39                printf("resume catch on terminate\n");
40        } catch (star *) {
41                printf("terminate catch on terminate\n");
42        }
43        printf("\n");
44
45        // Terminate does not catch resume.
46        try {
47                try {
48                        throwResume (star){&star_vt};
49                } catch (star *) {
50                        printf("terminate catch on resume\n");
51                }
52        } catch (star *) {
53                printf("terminate catch on resume\n");
54        } catchResume (star *) {
55                printf("resume catch on resume\n");
56        }
57        printf("\n");
58
59        // Resume a termination exception.
60        try {
61                try {
62                        try {
63                                throw (star){&star_vt};
64                        } catchResume (star *) {
65                                printf("inner resume catch (error)\n");
66                        }
67                } catch (star * error) {
68                        printf("termination catch, will resume\n");
69                        throwResume *error;
70                }
71        } catchResume (star *) {
72                printf("outer resume catch\n");
73        }
74        printf("\n");
75
76        // Terminate a resumption exception.
77        try {
78                try {
79                        try {
80                                throwResume (star){&star_vt};
81                        } catch (star *) {
82                                printf("inner termination catch\n");
83                        }
84                } catchResume (star * error) {
85                        printf("resumption catch, will terminate\n");
86                        throw *error;
87                }
88        } catch (star *) {
89                printf("outer terminate catch (error)\n");
90        }
91        printf("\n");
92
93        // Unwinding a resumption catch does not break the system.
94        try {
95                try {
96                        try {
97                                try {
98                                        printf("throwing resume moon\n");
99                                        throwResume (moon){&moon_vt};
100                                } catch (star *) {
101                                        printf("termination catch\n");
102                                }
103                                printf("throwing resume star\n");
104                                throwResume (star){&star_vt};
105                        } catchResume (star *) {
106                                printf("resumption star catch\n");
107                        }
108                } catchResume (moon *) {
109                        printf("resumption moon catch, will terminate\n");
110                        throw (star){&star_vt};
111                }
112        } catchResume (star *) {
113                printf("outermost catch (error)\n");
114        }
115}
Note: See TracBrowser for help on using the repository browser.