source:
tests/exceptions/conditional.cfa
@
efdd18c
Last change on this file since efdd18c was d00d581, checked in by , 3 years ago | |
---|---|
|
|
File size: 817 bytes |
Rev | Line | |
---|---|---|
[6d43cdde] | 1 | // Conditional Catch Test |
2 | ||
3 | // I may fold this back into terminate.cfa and resume.cfa once setting | |
4 | // up the non-trivial exception is reasonable to do. | |
5 | ||
[d00d581] | 6 | exception num_error { |
[ecfd758] | 7 | int num; |
[d00d581] | 8 | }; |
[6d43cdde] | 9 | |
[d00d581] | 10 | vtable(num_error) num_error_vt; |
[6d43cdde] | 11 | |
12 | void caught_num_error(int expect, num_error * actual) { | |
13 | printf("Caught num_error: expected=%d actual=%d.\n", expect, actual->num); | |
14 | } | |
15 | ||
16 | int main(int argc, char * argv[]) { | |
[ecfd758] | 17 | num_error exc = {&num_error_vt, 2}; |
[6d43cdde] | 18 | |
19 | try { | |
[046a890] | 20 | throw exc; |
[ecfd758] | 21 | } catch (num_error * error ; 3 == error->num ) { |
[6d43cdde] | 22 | caught_num_error(3, error); |
[ecfd758] | 23 | } catch (num_error * error ; 2 == error->num ) { |
[6d43cdde] | 24 | caught_num_error(2, error); |
25 | } | |
26 | ||
27 | try { | |
[046a890] | 28 | throwResume exc; |
[ecfd758] | 29 | } catchResume (num_error * error ; 3 == error->num ) { |
[6d43cdde] | 30 | caught_num_error(3, error); |
[ecfd758] | 31 | } catchResume (num_error * error ; 2 == error->num ) { |
[6d43cdde] | 32 | caught_num_error(2, error); |
33 | } | |
34 | } |
Note: See TracBrowser
for help on using the repository browser.