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