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