2
* test of catching a run-time exception
15
ret = test_catch_3(nil);
16
"back in _main: test_catch_3(nil) = <<ret>>\n";
18
ret = test_catch_3(true);
19
"back in _main: test_catch_3(true) = <<ret>>\n";
22
class Exception1: Exception
23
construct(msg) { msg_ = msg; }
25
display = "This is an Exception1 with message \"<<msg_>>\""
29
display { tadsSay(exceptionMessage); "\n"; }
32
function test_catch_1()
34
"test catch 1 - catch our own throw\n";
37
"about to throw our error...\n";
38
throw new Exception1('hello!');
40
"??? can't be here\n";
44
"test catch 1 - caught Exception1: << ex.display >>\n";
48
"test catch 1 - caught Exception: << th.display >>\n";
52
"test catch 1 - in finally\n";
56
function test_catch_2()
58
"test catch 2 - catching a VM error\n";
64
"about to generate an error...\n";
68
"??? shouldn't get here!";
72
"test catch 2 - caught Exception: << th.display >>\n";
76
"test catch 2 - in finally\n";
80
function test_catch_3(do_err)
82
"test catch 3 - catching an error while computing a return value\n";
86
"calculating our return value...\n";
87
return maybe_gen_err(do_err);
91
"test catch 3 - caught Exception: << th.display >>\n";
92
"returning 'error'\n";
97
function maybe_gen_err(do_err)
99
"... in maybe_gen_err\n";
104
"... causing a run-time error\n";
109
"... returning 'okay'\n";