cfad47cfa3/t3compiler/tads3/test/data/try_catch.t

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#include "tads.h"
2
#include "t3.h"
3
4
_main(args)
5
{
6
    t3SetSay(&_say_embed);
7
    a();
8
}
9
10
_say_embed(str) { tadsSay(str); }
11
12
class Exception: object
13
    construct(msg) { exceptionMessage = msg; }
14
    exceptionMessage = ''
15
;
16
17
class ResourceError: Exception;
18
class ParsingError: Exception;
19
20
21
a()
22
{
23
    b(1);
24
    b(2);
25
    b(3);
26
}
27
28
b(x)
29
{
30
    "This is b(<<x>>)\n";
31
    
32
    try
33
    {
34
        c(x);
35
    }
36
    catch (Exception exc)
37
    {
38
        "b: Caught an exception: <<exc.exceptionMessage>>\n";
39
    }
40
    
41
    "Done with b(<<x>>)\n";
42
}
43
44
c(x)
45
{
46
    "This is c(<<x>>)\n";
47
    
48
    try
49
    {
50
        d(x);
51
    }
52
    catch(ParsingError perr)
53
    {
54
        "c: Caught a parsing error: <<perr.exceptionMessage>>\n";
55
    }
56
    finally
57
    {
58
        "In c's finally clause\n";
59
    }
60
    
61
    "Done with c(<<x>>)\n";
62
}
63
64
d(x)
65
{
66
    "This is d(<<x>>)\n";
67
    e(x);
68
    "Done with d(<<x>>)\n";
69
}
70
71
e(x)
72
{
73
    "This is e(<<x>>)\n";
74
75
    if (x == 1)
76
    {
77
        "Throwing resource error...\n";
78
        throw new ResourceError('some resource error');
79
    }
80
    else if (x == 2)
81
    {
82
        "Throwing parsing error...\n";
83
        throw new ParsingError('some parsing error');
84
    }
85
    
86
    "Done with e(<<x>>)\n";
87
}