Debian Codegraph @

terps/tads/tads3/test/data/int_exc.t

raw
1 /*
2 * test of throwing an exception through a native code callback
3 */
4
5 #include "tads.h"
6 #include "t3.h"
7
8 preinit()
9 {
10 }
11
12 main(args)
13 {
14 local lst;
15
16 try
17 {
18 lst = [1, 2, 3, 4, 5];
19 lst = lst.mapAll(&f1);
20 }
21 catch (Exception exc)
22 {
23 "Back in main: caught exception: <<exc.displayException()>>\n";
24 }
25
26 try
27 {
28 lst = [5, 4, 3, 2, 1];
29 lst = lst.mapAll(&f1);
30 }
31 catch (Exception exc)
32 {
33 "Back in main: caught exception: <<exc.displayException()>>\n";
34 throw exc;
35 }
36 }
37
38 class F1Exception: Exception
39 displayException() { "f1: x = <<x_>>"; }
40 construct(x) { x_ = x; }
41 x_ = nil
42 ;
43
44 f1(x)
45 {
46 "f1(<<x>>)\n";
47 if (x == 3)
48 throw new F1Exception(x);
49 }
50