1 -{ extension 'trycatch' }
4 ----------------------------------------------------------------------
11 ----------------------------------------------------------------------
12 print "2) caught error"
16 printf(" Successfully caught %q", x)
21 ----------------------------------------------------------------------
22 print "3) no error, with a finally"
30 ----------------------------------------------------------------------
31 print "4) error, with a finally"
42 ----------------------------------------------------------------------
43 print "5) nested catchers"
47 catch "some_other_error" then
48 assert (false, "mismatch, this must not happen")
50 catch "some_error"/x then
51 printf(" Successfully caught %q across a try that didn't catch", x)
53 assert (false, "We shouldn't reach this catch-all")
57 ----------------------------------------------------------------------
58 print "6) nested catchers, with a 'finally in the inner one"
62 catch "some_other_error" then
63 assert (false, "mismatch, this must not happen")
65 print " Leaving the inner try-catch"
67 catch "some_error"/{x} then
68 printf(" Successfully caught %q across a try that didn't catch", x)
70 assert (false, "We shouldn't reach this catch-all")
74 ----------------------------------------------------------------------
75 print "7) 'finally' intercepts a return from a function"
80 assert (false, "I'll never go there")
82 assert (false, "No exception should be thrown")
84 print " I do the finally before leaving f()"
88 printf(" f returned %q", fr)
91 ----------------------------------------------------------------------
92 print "8) don't be fooled by nested functions"
95 local function g() return "from g" end
96 printf(" g() returns %q", g())
99 assert (false, "No exception should be thrown")
103 printf(" f returned %q", fr)
105 ----------------------------------------------------------------------