UNPKG

737 Btext/coffeescriptView Raw
1suite 'Try/Catch/Finally', ->
2
3 test 'simple try-catch-finally', ->
4 t = c = f = 0
5 try
6 ++t
7 throw {}
8 catch e
9 ++c
10 finally
11 ++f
12 eq 1, t
13 eq 1, c
14 eq 1, f
15
16 t = c = f = 0
17 try
18 ++t
19 catch e
20 # catch should not be executed if nothing is thrown
21 ++c
22 finally
23 # but finally should always be executed
24 ++f
25 eq 1, t
26 eq 0, c
27 eq 1, f
28
29 test 'try without catch just suppresses thrown errors', ->
30 try throw {}
31
32 test 'catch variable is not let-scoped as in JS', ->
33 nonce = {}
34 try throw nonce
35 catch e then
36 eq nonce, e
37
38 test 'destructuring in catch', ->
39 nonce = {}
40 try throw {nonce}
41 catch {nonce: a}
42 eq nonce, a