source: tests/exceptions/interact.cfa@ c715e5f

ADT ast-experimental pthread-emulation qualifiedEnum
Last change on this file since c715e5f was d00d581, checked in by Henry Xue <y58xue@…>, 4 years ago

Update exception tests to use new syntax

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