source: tests/exceptions/conditional.cfa @ 6065281f

Last change on this file since 6065281f was 3bf9d10, checked in by Peter A. Buhr <pabuhr@…>, 11 months ago

change printf to sout

  • Property mode set to 100644
File size: 845 bytes
RevLine 
[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
[3bf9d10]6#include <fstream.cfa>
7
[d00d581]8exception num_error {
[ecfd758]9        int num;
[d00d581]10};
[6d43cdde]11
[d00d581]12vtable(num_error) num_error_vt;
[6d43cdde]13
14void caught_num_error(int expect, num_error * actual) {
[3bf9d10]15        sout | "Caught num_error: expected=" | expect | "actual=" | actual->num | '.';
[6d43cdde]16}
17
18int 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.