source: tests/exceptions/resume.cfa@ 73530d9

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 73530d9 was 3eb5a478, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Fixed the disabled exceptions/resume test. Added more tests in exceptions/interact, one of which is disabled.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1// Resumption Exception Tests
2
3#include "except-mac.hfa"
4#include "except-io.hfa"
5
6TRIVIAL_EXCEPTION(yin);
7TRIVIAL_EXCEPTION(yang);
8TRIVIAL_EXCEPTION(zen);
9TRIVIAL_EXCEPTION(moment_of, zen);
10
11int main(int argc, char * argv[]) {
12 // The simple throw catchResume test.
13 try {
14 loud_exit a = "simple try clause";
15 printf("simple throw\n");
16 THROW_RESUME(&(zen){});
17 printf("end of try clause\n");
18 } catchResume (zen * error) {
19 loud_exit a = "simple catch clause";
20 printf("simple catch\n");
21 }
22 printf("\n");
23
24 // Catch a parent of the given exception.
25 try {
26 printf("throwing child exception\n");
27 THROW_RESUME(&(moment_of){});
28 } catchResume (zen *) {
29 printf("inner parent match\n");
30 } catchResume (moment_of *) {
31 printf("outer exact match\n");
32 }
33 printf("\n");
34
35 // Don't catch if handler does not match exception.
36 try {
37 try {
38 THROW_RESUME(&(yin){});
39 } catchResume (zen *) {
40 printf("caught yin as zen\n");
41 }
42 } catchResume (yang *) {
43 printf("caught yin as yang\n");
44 } catchResume (yin *) {
45 printf("caught yin as yin\n");
46 }
47 printf("\n");
48
49 // Test rethrowing an exception.
50 try {
51 try {
52 loud_exit a = "rethrow inner try";
53 printf("rethrow inner try\n");
54 THROW_RESUME(&(zen){});
55 } catchResume (zen *) {
56 loud_exit a = "rethrowing catch clause";
57 printf("caught throw, will rethrow\n");
58 throwResume;
59 }
60 } catchResume (zen *) {
61 loud_exit a = "rethrow catch clause";
62 printf("caught rethrow\n");
63 }
64 printf("\n");
65
66 // Throw a different exception in a catch.
67 try {
68 try {
69 THROW_RESUME(&(yin){});
70 } catchResume (yin *) {
71 printf("caught yin, will throw yang\n");
72 THROW_RESUME(&(yang){});
73 } catchResume (yang *) {
74 printf("caught exception from same try\n");
75 }
76 } catchResume (yang *) {
77 printf("caught yang\n");
78 }
79 printf("\n");
80
81 // Another throw in the catch does not interfere.
82 try {
83 try {
84 printf("throwing first exception\n");
85 THROW_RESUME(&(yin){});
86 } catchResume (yin *) {
87 printf("caught first exception\n");
88 try {
89 printf("throwing second exception\n");
90 THROW_RESUME(&(yang){});
91 } catchResume (yang *) {
92 printf("caught second exception\n");
93 }
94 throwResume;
95 }
96 } catchResume (yin *) {
97 printf("recaught first exception\n");
98 } catchResume (yang *) {
99 printf("caught second exception (bad location)\n");
100 }
101}
Note: See TracBrowser for help on using the repository browser.