source:
tests/exceptions/conditional.cfa
@
bfa7bf0
Last change on this file since bfa7bf0 was fe0b94f, checked in by , 17 months ago | |
---|---|
|
|
File size: 845 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 | ||
[fe0b94f] | 6 | #include <fstream.hfa> |
[3bf9d10] | 7 | |
[d00d581] | 8 | exception num_error { |
[ecfd758] | 9 | int num; |
[d00d581] | 10 | }; |
[6d43cdde] | 11 | |
[d00d581] | 12 | vtable(num_error) num_error_vt; |
[6d43cdde] | 13 | |
14 | void caught_num_error(int expect, num_error * actual) { | |
[3bf9d10] | 15 | sout | "Caught num_error: expected=" | expect | "actual=" | actual->num | '.'; |
[6d43cdde] | 16 | } |
17 | ||
18 | int main(int argc, char * argv[]) { | |
[ecfd758] | 19 | num_error exc = {&num_error_vt, 2}; |
[6d43cdde] | 20 | |
21 | try { | |
[046a890] | 22 | throw exc; |
[ecfd758] | 23 | } catch (num_error * error ; 3 == error->num ) { |
[6d43cdde] | 24 | caught_num_error(3, error); |
[ecfd758] | 25 | } catch (num_error * error ; 2 == error->num ) { |
[6d43cdde] | 26 | caught_num_error(2, error); |
27 | } | |
28 | ||
29 | try { | |
[046a890] | 30 | throwResume exc; |
[ecfd758] | 31 | } catchResume (num_error * error ; 3 == error->num ) { |
[6d43cdde] | 32 | caught_num_error(3, error); |
[ecfd758] | 33 | } catchResume (num_error * error ; 2 == error->num ) { |
[6d43cdde] | 34 | caught_num_error(2, error); |
35 | } | |
36 | } |
Note: See TracBrowser
for help on using the repository browser.