[6d43cdde] | 1 | // Testing Interactions Between Termination and Resumption |
---|
| 2 | |
---|
[e68d092] | 3 | #include <exception.hfa> |
---|
[6d43cdde] | 4 | #include "except-io.hfa" |
---|
| 5 | |
---|
| 6 | TRIVIAL_EXCEPTION(star); |
---|
[3eb5a478] | 7 | TRIVIAL_EXCEPTION(moon); |
---|
[6d43cdde] | 8 | |
---|
| 9 | int main(int argc, char * argv[]) { |
---|
| 10 | // Resume falls back to terminate. |
---|
| 11 | try { |
---|
[046a890] | 12 | throwResume (star){}; |
---|
[6d43cdde] | 13 | } catch (star *) { |
---|
| 14 | printf("caught as termination\n"); |
---|
| 15 | } |
---|
| 16 | // Variant of the above to check timing. |
---|
| 17 | try { |
---|
| 18 | loud_region a = "try block with resume throw"; |
---|
[046a890] | 19 | throwResume (star){}; |
---|
[6d43cdde] | 20 | } catch (star *) { |
---|
| 21 | printf("caught as termination\n"); |
---|
| 22 | } catchResume (star *) { |
---|
| 23 | printf("intermediate rethrow\n"); |
---|
| 24 | throwResume; |
---|
| 25 | } |
---|
| 26 | printf("\n"); |
---|
| 27 | |
---|
| 28 | // Resume does not catch terminate. |
---|
| 29 | try { |
---|
| 30 | try { |
---|
[046a890] | 31 | throw (star){}; |
---|
[6d43cdde] | 32 | } catchResume (star *) { |
---|
| 33 | printf("resume catch on terminate\n"); |
---|
| 34 | } |
---|
| 35 | } catchResume (star *) { |
---|
| 36 | printf("resume catch on terminate\n"); |
---|
| 37 | } catch (star *) { |
---|
| 38 | printf("terminate catch on terminate\n"); |
---|
| 39 | } |
---|
| 40 | printf("\n"); |
---|
| 41 | |
---|
| 42 | // Terminate does not catch resume. |
---|
| 43 | try { |
---|
| 44 | try { |
---|
[046a890] | 45 | throwResume (star){}; |
---|
[6d43cdde] | 46 | } catch (star *) { |
---|
| 47 | printf("terminate catch on resume\n"); |
---|
| 48 | } |
---|
| 49 | } catch (star *) { |
---|
| 50 | printf("terminate catch on resume\n"); |
---|
| 51 | } catchResume (star *) { |
---|
| 52 | printf("resume catch on resume\n"); |
---|
| 53 | } |
---|
[3eb5a478] | 54 | printf("\n"); |
---|
| 55 | |
---|
| 56 | // Resume a termination exception. |
---|
| 57 | try { |
---|
| 58 | try { |
---|
| 59 | try { |
---|
[046a890] | 60 | throw (star){}; |
---|
[3eb5a478] | 61 | } catchResume (star *) { |
---|
| 62 | printf("inner resume catch (error)\n"); |
---|
| 63 | } |
---|
| 64 | } catch (star * error) { |
---|
| 65 | printf("termination catch, will resume\n"); |
---|
[046a890] | 66 | throwResume *error; |
---|
[3eb5a478] | 67 | } |
---|
| 68 | } catchResume (star *) { |
---|
| 69 | printf("outer resume catch\n"); |
---|
| 70 | } |
---|
| 71 | printf("\n"); |
---|
| 72 | |
---|
| 73 | // Terminate a resumption exception. |
---|
| 74 | try { |
---|
| 75 | try { |
---|
| 76 | try { |
---|
[046a890] | 77 | throwResume (star){}; |
---|
[3eb5a478] | 78 | } catch (star *) { |
---|
| 79 | printf("inner termination catch\n"); |
---|
| 80 | } |
---|
| 81 | } catchResume (star * error) { |
---|
| 82 | printf("resumption catch, will terminate\n"); |
---|
[046a890] | 83 | throw *error; |
---|
[3eb5a478] | 84 | } |
---|
| 85 | } catch (star *) { |
---|
| 86 | printf("outer terminate catch (error)\n"); |
---|
| 87 | } |
---|
| 88 | printf("\n"); |
---|
| 89 | |
---|
| 90 | // Unwinding a resumption catch does not break the system. |
---|
| 91 | try { |
---|
| 92 | try { |
---|
| 93 | try { |
---|
| 94 | try { |
---|
| 95 | printf("throwing resume moon\n"); |
---|
[046a890] | 96 | throwResume (moon){}; |
---|
[3eb5a478] | 97 | } catch (star *) { |
---|
| 98 | printf("termination catch\n"); |
---|
| 99 | } |
---|
| 100 | printf("throwing resume star\n"); |
---|
[046a890] | 101 | throwResume (star){}; |
---|
[3eb5a478] | 102 | } catchResume (star *) { |
---|
| 103 | printf("resumption star catch\n"); |
---|
| 104 | } |
---|
| 105 | } catchResume (moon *) { |
---|
| 106 | printf("resumption moon catch, will terminate\n"); |
---|
[046a890] | 107 | throw (star){}; |
---|
[3eb5a478] | 108 | } |
---|
| 109 | } catchResume (star *) { |
---|
| 110 | printf("outermost catch (error)\n"); |
---|
| 111 | } |
---|
[6d43cdde] | 112 | } |
---|