source: tests/exceptions/resume.cfa @ 6d43cdde

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

Rework of exception tests. Includes a new disabled failing test case.

  • 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#ifdef FAILING
80        printf("\n");
81
82        // Another throw in the catch does not interfere.
83        try {
84                try {
85                        printf("throwing first exception\n");
86                        THROW_RESUME(&(yin){});
87                } catchResume (yin *) {
88                        printf("caught first exception\n");
89                        try {
90                                printf("throwing second exception\n");
91                                THROW_RESUME(&(yang){});
92                        } catchResume (yang *) {
93                                printf("caught second exception\n");
94                        }
95                        throwResume;
96                }
97        } catchResume (yin *) {
98                printf("recaught first exception\n");
99        } catchResume (yang *) {
100                printf("caught second exception (bad location)\n");
101        }
102#endif
103}
Note: See TracBrowser for help on using the repository browser.