source: tests/exceptions/interact.cfa @ b59c21a

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

change printf to sout

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