6.18 Exceptions
expression | ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
|
If an excepotion is thrown during the the body sequence, the control escapes to the context of the try body sequence (i.e., “inside” the ~initially and ~finally guards) and the ~catch cases are tried in order. When a ~catch binding matches, then the result of the try form is the body of the ~catch clause. If no ~catch clause matches, the exception is re-thrown. Breaks are disabled while attempting to match a ~catch clause or evaluating its body.
The last body form of try are not in tail position is any of ~initially, ~catch, or ~finally is present. If none are present, the try form is the same as begin.
> try:
1/0
~catch exn :: Exn.Fail.Contract.DivideByZero:
"handled"
"handled"
> try:
~initially: println("in")
1/0
~catch _:
println("ignoring all exceptions!")
0
~finally: println("out")
in
ignoring all exceptions!
out
0
> def k:
try:
~initially: println("in")
Continuation.capture k: k
~finally: println("out")
in
out
> k("again")
in
out
"again"
function | ||||
| ||||
| ||||
function | ||||
|
class | ||
class Exn(message :: ReadableString, marks :: Continuation.Marks) | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
class | ||
| ||
| ||
class | ||
| ||
class | ||