2010-04-03 10:39:32 -04:00
|
|
|
# Basic exception throwing.
|
2010-10-19 02:32:23 -04:00
|
|
|
block = -> throw 'up'
|
2010-04-03 10:39:32 -04:00
|
|
|
throws block, 'up'
|
|
|
|
|
|
|
|
|
|
|
|
# Basic try/catch.
|
2010-07-25 01:23:37 -04:00
|
|
|
result = try
|
2010-04-03 10:39:32 -04:00
|
|
|
10
|
|
|
|
finally
|
|
|
|
15
|
|
|
|
|
|
|
|
ok result is 10
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
result = try
|
2010-04-03 10:39:32 -04:00
|
|
|
throw 'up'
|
|
|
|
catch err
|
|
|
|
err.length
|
|
|
|
|
2010-06-28 08:50:44 -04:00
|
|
|
ok result is 2
|
|
|
|
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
result = try throw 'error' catch err then err.length
|
2010-06-28 08:50:44 -04:00
|
|
|
|
2010-06-30 20:53:09 -04:00
|
|
|
ok result is 5
|
|
|
|
|
2010-10-04 16:53:32 -04:00
|
|
|
try throw 'catch is optional'
|
2010-06-30 20:53:09 -04:00
|
|
|
|
|
|
|
# try/catch with empty clauses still compiles.
|
2010-10-04 16:53:32 -04:00
|
|
|
try
|
|
|
|
|
2010-06-30 20:53:09 -04:00
|
|
|
try
|
|
|
|
# nothing
|
|
|
|
catch err
|
2010-07-04 12:50:04 -04:00
|
|
|
# nothing
|
|
|
|
|
|
|
|
try
|
|
|
|
# nothing
|
|
|
|
finally
|
|
|
|
# nothing
|
|
|
|
|
2010-07-13 23:33:59 -04:00
|
|
|
try
|
|
|
|
catch err
|
|
|
|
finally
|
|
|
|
|
2010-10-04 16:53:32 -04:00
|
|
|
ok yes
|
2010-10-27 22:21:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Try catch with empty clause in a function body.
|
|
|
|
func = ->
|
|
|
|
try
|
|
|
|
100
|
|
|
|
catch err
|
|
|
|
|
|
|
|
ok func() is 100
|