10.2 Exceptions
expression | ||||||||||||||
| ||||||||||||||
| ||||||||||||||
| ||||||||||||||
| ||||||||||||||
| ||||||||||||||
| ||||||||||||||
|
Returns the value(s) of the body sequence, but runs the body or expression of an ~initially clause when entering the try body (whether normally or by a continuation jump) and the body or expression of a ~finally clause when leaving the try body (whether normally or by a continuation jump, including exception throws).
If an exception 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(block:
println("pre")
"again")
pre
in
out
"again"
> Continuation.in k:
println("body")
"again"
in
body
out
"again"
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 | ||
| ||
class | ||
| ||
class | ||