try
9.0
top
← prev up next →

try-catch-matchπŸ”— i

Benedek Szilvasy

A try-catch-finally macro that binds with match.

syntax

( try body...+catch-clause...maybe-finally-clause)

catch-clause = (catch patbody...+)
maybe-finally-clause =
| (finally body...+)
try to evaluate body expressions, returning the last one on success.

If an exception is raise d, then attempt to match one of the pats in the catch clauses, returning the result of its body. If none of them match, the exception is re-raised.

If there is a finally clause present, it will be executed when exiting the body, through a normal return, uncaught exception or a continuation.

syntax

( catch patbody...+)

A catch clause, executes and returns body if pat matches a raised exception.

syntax

( finally body...+)

Evaluated before try returns.

Examples:
> (try
(raise "raised string")
(catch (?string? e)
(display "Caught: "(current-error-port ))

Caught: raised string

> (try
(cons 1)
(catch (or (?exn? (appexn-message msg))
(app~amsg))
msg))

"cons: arity mismatch;\n the expected number of arguments does not match the given number\nexpected: 2\ngiven: 1"

(lambda (cc)
(try
(cc"Escaped")
(displayln "Escaping"))))))

Escaping

Escaped

syntax

( try-with ([idval]...)body...+)

Like let , bind ids to vals in body. vals are evaluated with current-custodian set to a new custodian created with make-custodian . When the expression returns, the custodian is shutdown with custodian-shutdown-all in a finally clause.

Example:

x

#f

syntax

( try-with* ([idval]...)body...+)

Like try-with , but the binding of each id is made available in subsequent vals, as in let* . All vals are evaluated with the same custodian.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /