source: tests/exceptions/interact.cfa

Last change on this file was 3bf9d10, checked in by Peter A. Buhr <pabuhr@…>, 9 months ago

change printf to sout

  • Property mode set to 100644
File size: 2.4 KB
Line 
1// Testing Interactions Between Termination and Resumption
2
3#include <fstream.hfa>
4#include "except-io.hfa"
5
6exception star {};
7exception moon {};
8
9vtable(star) star_vt;
10vtable(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                sout | "caught as termination";
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                sout | "caught as termination";
25        } catchResume (star *) {
26                sout | "intermediate rethrow";
27                throwResume;
28        }
29        sout | nl;
30
31        // Resume does not catch terminate.
32        try {
33                try {
34                        throw (star){&star_vt};
35                } catchResume (star *) {
36                        sout | "resume catch on terminate";
37                }
38        } catchResume (star *) {
39                sout | "resume catch on terminate";
40        } catch (star *) {
41                sout | "terminate catch on terminate";
42        }
43        sout | nl;
44
45        // Terminate does not catch resume.
46        try {
47                try {
48                        throwResume (star){&star_vt};
49                } catch (star *) {
50                        sout | "terminate catch on resume";
51                }
52        } catch (star *) {
53                sout | "terminate catch on resume";
54        } catchResume (star *) {
55                sout | "resume catch on resume";
56        }
57        sout | nl;
58
59        // Resume a termination exception.
60        try {
61                try {
62                        try {
63                                throw (star){&star_vt};
64                        } catchResume (star *) {
65                                sout | "inner resume catch (error)";
66                        }
67                } catch (star * error) {
68                        sout | "termination catch, will resume";
69                        throwResume *error;
70                }
71        } catchResume (star *) {
72                sout | "outer resume catch";
73        }
74        sout | nl;
75
76        // Terminate a resumption exception.
77        try {
78                try {
79                        try {
80                                throwResume (star){&star_vt};
81                        } catch (star *) {
82                                sout | "inner termination catch";
83                        }
84                } catchResume (star * error) {
85                        sout | "resumption catch, will terminate";
86                        throw *error;
87                }
88        } catch (star *) {
89                sout | "outer terminate catch (error)";
90        }
91        sout | nl;
92
93        // Unwinding a resumption catch does not break the system.
94        try {
95                try {
96                        try {
97                                try {
98                                        sout | "throwing resume moon";
99                                        throwResume (moon){&moon_vt};
100                                } catch (star *) {
101                                        sout | "termination catch";
102                                }
103                                sout | "throwing resume star";
104                                throwResume (star){&star_vt};
105                        } catchResume (star *) {
106                                sout | "resumption star catch";
107                        }
108                } catchResume (moon *) {
109                        sout | "resumption moon catch, will terminate";
110                        throw (star){&star_vt};
111                }
112        } catchResume (star *) {
113                sout | "outermost catch (error)";
114        }
115}
Note: See TracBrowser for help on using the repository browser.