[6d43cdde] | 1 | // Resumption Exception Tests |
---|
| 2 | |
---|
[e68d092] | 3 | #include <exception.hfa> |
---|
[6d43cdde] | 4 | #include "except-io.hfa" |
---|
| 5 | |
---|
| 6 | TRIVIAL_EXCEPTION(yin); |
---|
| 7 | TRIVIAL_EXCEPTION(yang); |
---|
| 8 | TRIVIAL_EXCEPTION(zen); |
---|
| 9 | TRIVIAL_EXCEPTION(moment_of, zen); |
---|
| 10 | |
---|
| 11 | int 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"); |
---|
[e68d092] | 16 | throwResume &(zen){}; |
---|
[6d43cdde] | 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"); |
---|
[e68d092] | 27 | throwResume &(moment_of){}; |
---|
[6d43cdde] | 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 { |
---|
[e68d092] | 38 | throwResume &(yin){}; |
---|
[6d43cdde] | 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"); |
---|
[e68d092] | 54 | throwResume &(zen){}; |
---|
[6d43cdde] | 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 { |
---|
[e68d092] | 69 | throwResume &(yin){}; |
---|
[6d43cdde] | 70 | } catchResume (yin *) { |
---|
| 71 | printf("caught yin, will throw yang\n"); |
---|
[e68d092] | 72 | throwResume &(yang){}; |
---|
[6d43cdde] | 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"); |
---|
[e68d092] | 85 | throwResume &(yin){}; |
---|
[6d43cdde] | 86 | } catchResume (yin *) { |
---|
| 87 | printf("caught first exception\n"); |
---|
| 88 | try { |
---|
| 89 | printf("throwing second exception\n"); |
---|
[e68d092] | 90 | throwResume &(yang){}; |
---|
[6d43cdde] | 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 | } |
---|
[f1b6671] | 101 | printf("\n"); |
---|
| 102 | |
---|
| 103 | // Check successive operations. |
---|
| 104 | try { |
---|
| 105 | try { |
---|
[e68d092] | 106 | throwResume &(zen){}; |
---|
| 107 | throwResume &(zen){}; |
---|
[f1b6671] | 108 | } catchResume (zen *) { |
---|
| 109 | printf("inner catch\n"); |
---|
| 110 | } |
---|
[e68d092] | 111 | throwResume &(zen){}; |
---|
[f1b6671] | 112 | } catchResume (zen *) { |
---|
| 113 | printf("outer catch\n"); |
---|
| 114 | } |
---|
[6d43cdde] | 115 | } |
---|