[6d43cdde] | 1 | // Resumption Exception Tests |
---|
| 2 | |
---|
[e68d092] | 3 | #include <exception.hfa> |
---|
[6d43cdde] | 4 | #include "except-io.hfa" |
---|
| 5 | |
---|
[ecfd758] | 6 | EHM_EXCEPTION(yin)(); |
---|
| 7 | EHM_EXCEPTION(yang)(); |
---|
| 8 | EHM_EXCEPTION(zen)(); |
---|
| 9 | |
---|
| 10 | EHM_VIRTUAL_TABLE(yin, yin_vt); |
---|
| 11 | EHM_VIRTUAL_TABLE(yang, yang_vt); |
---|
| 12 | EHM_VIRTUAL_TABLE(zen, zen_vt); |
---|
[6d43cdde] | 13 | |
---|
[7f9968a] | 14 | void in_void(void); |
---|
| 15 | |
---|
[6d43cdde] | 16 | int main(int argc, char * argv[]) { |
---|
[ecfd758] | 17 | yin a_yin = {&yin_vt}; |
---|
| 18 | yang a_yang = {&yang_vt}; |
---|
| 19 | zen a_zen = {&zen_vt}; |
---|
| 20 | |
---|
[6d43cdde] | 21 | // The simple throw catchResume test. |
---|
| 22 | try { |
---|
| 23 | loud_exit a = "simple try clause"; |
---|
| 24 | printf("simple throw\n"); |
---|
[ecfd758] | 25 | throwResume a_zen; |
---|
[6d43cdde] | 26 | printf("end of try clause\n"); |
---|
| 27 | } catchResume (zen * error) { |
---|
| 28 | loud_exit a = "simple catch clause"; |
---|
| 29 | printf("simple catch\n"); |
---|
| 30 | } |
---|
| 31 | printf("\n"); |
---|
| 32 | |
---|
[fe1025d] | 33 | // Throw catch-all test. |
---|
| 34 | try { |
---|
[ecfd758] | 35 | throwResume a_zen; |
---|
[fe1025d] | 36 | } catchResume (exception_t * error) { |
---|
| 37 | printf("catch-all\n"); |
---|
| 38 | } |
---|
| 39 | printf("\n"); |
---|
| 40 | |
---|
[6d43cdde] | 41 | // Don't catch if handler does not match exception. |
---|
| 42 | try { |
---|
| 43 | try { |
---|
[ecfd758] | 44 | throwResume a_yin; |
---|
[6d43cdde] | 45 | } catchResume (zen *) { |
---|
| 46 | printf("caught yin as zen\n"); |
---|
| 47 | } |
---|
| 48 | } catchResume (yang *) { |
---|
| 49 | printf("caught yin as yang\n"); |
---|
| 50 | } catchResume (yin *) { |
---|
| 51 | printf("caught yin as yin\n"); |
---|
| 52 | } |
---|
| 53 | printf("\n"); |
---|
| 54 | |
---|
| 55 | // Test rethrowing an exception. |
---|
| 56 | try { |
---|
| 57 | try { |
---|
| 58 | loud_exit a = "rethrow inner try"; |
---|
| 59 | printf("rethrow inner try\n"); |
---|
[ecfd758] | 60 | throwResume a_zen; |
---|
[6d43cdde] | 61 | } catchResume (zen *) { |
---|
| 62 | loud_exit a = "rethrowing catch clause"; |
---|
| 63 | printf("caught throw, will rethrow\n"); |
---|
| 64 | throwResume; |
---|
| 65 | } |
---|
| 66 | } catchResume (zen *) { |
---|
| 67 | loud_exit a = "rethrow catch clause"; |
---|
| 68 | printf("caught rethrow\n"); |
---|
| 69 | } |
---|
| 70 | printf("\n"); |
---|
| 71 | |
---|
| 72 | // Throw a different exception in a catch. |
---|
| 73 | try { |
---|
| 74 | try { |
---|
[ecfd758] | 75 | throwResume a_yin; |
---|
[6d43cdde] | 76 | } catchResume (yin *) { |
---|
| 77 | printf("caught yin, will throw yang\n"); |
---|
[ecfd758] | 78 | throwResume a_yang; |
---|
[6d43cdde] | 79 | } catchResume (yang *) { |
---|
| 80 | printf("caught exception from same try\n"); |
---|
| 81 | } |
---|
| 82 | } catchResume (yang *) { |
---|
| 83 | printf("caught yang\n"); |
---|
| 84 | } |
---|
| 85 | printf("\n"); |
---|
| 86 | |
---|
| 87 | // Another throw in the catch does not interfere. |
---|
| 88 | try { |
---|
| 89 | try { |
---|
| 90 | printf("throwing first exception\n"); |
---|
[ecfd758] | 91 | throwResume a_yin; |
---|
[6d43cdde] | 92 | } catchResume (yin *) { |
---|
| 93 | printf("caught first exception\n"); |
---|
| 94 | try { |
---|
| 95 | printf("throwing second exception\n"); |
---|
[ecfd758] | 96 | throwResume a_yang; |
---|
[6d43cdde] | 97 | } catchResume (yang *) { |
---|
| 98 | printf("caught second exception\n"); |
---|
| 99 | } |
---|
| 100 | throwResume; |
---|
| 101 | } |
---|
| 102 | } catchResume (yin *) { |
---|
| 103 | printf("recaught first exception\n"); |
---|
| 104 | } catchResume (yang *) { |
---|
| 105 | printf("caught second exception (bad location)\n"); |
---|
| 106 | } |
---|
[f1b6671] | 107 | printf("\n"); |
---|
| 108 | |
---|
| 109 | // Check successive operations. |
---|
| 110 | try { |
---|
| 111 | try { |
---|
[ecfd758] | 112 | throwResume a_zen; |
---|
| 113 | throwResume a_zen; |
---|
[f1b6671] | 114 | } catchResume (zen *) { |
---|
| 115 | printf("inner catch\n"); |
---|
| 116 | } |
---|
[ecfd758] | 117 | throwResume a_zen; |
---|
[f1b6671] | 118 | } catchResume (zen *) { |
---|
| 119 | printf("outer catch\n"); |
---|
| 120 | } |
---|
[7f9968a] | 121 | printf("\n"); |
---|
| 122 | |
---|
| 123 | in_void(); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // Do a throw and rethrow in a void function. |
---|
| 127 | void in_void(void) { |
---|
[ecfd758] | 128 | zen a_zen = {&zen_vt}; |
---|
[7f9968a] | 129 | try { |
---|
| 130 | try { |
---|
| 131 | printf("throw\n"); |
---|
[ecfd758] | 132 | throwResume a_zen; |
---|
[7f9968a] | 133 | } catchResume (zen *) { |
---|
| 134 | printf("rethrow\n"); |
---|
| 135 | throwResume; |
---|
| 136 | } |
---|
| 137 | } catchResume (zen *) { |
---|
| 138 | printf("handle\n"); |
---|
| 139 | } |
---|
[6d43cdde] | 140 | } |
---|