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