source: tests/exceptions/terminate.cfa@ 1cf2a9b

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 1cf2a9b was e68d092, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Replaced my exception patch macros with a (hopefully temporary) addition to the standard libary, the same macros just cleaned up. See the exception tests for some example uses.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1// Termination 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 catch test.
13 try {
14 loud_exit a = "simple try clause";
15 printf("simple throw\n");
16 throw &(zen){};
17 printf("end of try clause\n");
18 } catch (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 &(moment_of){};
28 } catch (zen *) {
29 printf("inner parent match\n");
30 } catch (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 &(yin){};
39 } catch (zen *) {
40 printf("caught yin as zen\n");
41 }
42 } catch (yang *) {
43 printf("caught yin as yang\n");
44 } catch (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 &(zen){};
55 } catch (zen *) {
56 loud_exit a = "rethrowing catch clause";
57 printf("caught throw, will rethrow\n");
58 throw;
59 }
60 } catch (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 &(yin){};
70 } catch (yin *) {
71 printf("caught yin, will throw yang\n");
72 throw &(yang){};
73 } catch (yang *) {
74 printf("caught exception from same try\n");
75 }
76 } catch (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 &(yin){};
86 } catch (yin *) {
87 printf("caught first exception\n");
88 try {
89 printf("throwing second exception\n");
90 throw &(yang){};
91 } catch (yang *) {
92 printf("caught second exception\n");
93 }
94 throw;
95 }
96 } catch (yin *) {
97 printf("recaught first exception\n");
98 } catch (yang *) {
99 printf("caught second exception (bad location)\n");
100 }
101 printf("\n");
102
103 // Check successive operations.
104 try {
105 try {
106 throw &(zen){};
107 throw &(zen){};
108 } catch (zen *) {
109 printf("inner catch\n");
110 }
111 throw &(zen){};
112 } catch (zen *) {
113 printf("outer catch\n");
114 }
115}
Note: See TracBrowser for help on using the repository browser.