source: tests/exceptions/resume.cfa @ 730f4f1

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 730f4f1 was fe1025d, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added catch-all tests to the exception tests.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1// Resumption Exception Tests
2
3#include <exception.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                throwResume &(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        // Throw catch-all test.
25        try {
26                throwResume &(zen){};
27        } catchResume (exception_t * error) {
28                printf("catch-all\n");
29        }
30        printf("\n");
31
32        // Catch a parent of the given exception.
33        try {
34                printf("throwing child exception\n");
35                throwResume &(moment_of){};
36        } catchResume (zen *) {
37                printf("inner parent match\n");
38        } catchResume (moment_of *) {
39                printf("outer exact match\n");
40        }
41        printf("\n");
42
43        // Don't catch if handler does not match exception.
44        try {
45                try {
46                        throwResume &(yin){};
47                } catchResume (zen *) {
48                        printf("caught yin as zen\n");
49                }
50        } catchResume (yang *) {
51                printf("caught yin as yang\n");
52        } catchResume (yin *) {
53                printf("caught yin as yin\n");
54        }
55        printf("\n");
56
57        // Test rethrowing an exception.
58        try {
59                try {
60                        loud_exit a = "rethrow inner try";
61                        printf("rethrow inner try\n");
62                        throwResume &(zen){};
63                } catchResume (zen *) {
64                        loud_exit a = "rethrowing catch clause";
65                        printf("caught throw, will rethrow\n");
66                        throwResume;
67                }
68        } catchResume (zen *) {
69                loud_exit a = "rethrow catch clause";
70                printf("caught rethrow\n");
71        }
72        printf("\n");
73
74        // Throw a different exception in a catch.
75        try {
76                try {
77                        throwResume &(yin){};
78                } catchResume (yin *) {
79                        printf("caught yin, will throw yang\n");
80                        throwResume &(yang){};
81                } catchResume (yang *) {
82                        printf("caught exception from same try\n");
83                }
84        } catchResume (yang *) {
85                printf("caught yang\n");
86        }
87        printf("\n");
88
89        // Another throw in the catch does not interfere.
90        try {
91                try {
92                        printf("throwing first exception\n");
93                        throwResume &(yin){};
94                } catchResume (yin *) {
95                        printf("caught first exception\n");
96                        try {
97                                printf("throwing second exception\n");
98                                throwResume &(yang){};
99                        } catchResume (yang *) {
100                                printf("caught second exception\n");
101                        }
102                        throwResume;
103                }
104        } catchResume (yin *) {
105                printf("recaught first exception\n");
106        } catchResume (yang *) {
107                printf("caught second exception (bad location)\n");
108        }
109        printf("\n");
110
111        // Check successive operations.
112        try {
113                try {
114                        throwResume &(zen){};
115                        throwResume &(zen){};
116                } catchResume (zen *) {
117                        printf("inner catch\n");
118                }
119                throwResume &(zen){};
120        } catchResume (zen *) {
121                printf("outer catch\n");
122        }
123}
Note: See TracBrowser for help on using the repository browser.