Function: catch
key
thunk
handler
Invoke
thunk
in the dynamic context ofhandler
for exceptions matchingkey
. If thunk throws to the symbolkey
, thenhandler
is invoked this way:(handler key args ...)
key
may be a symbol. Thethunk
takes no arguments. Ifthunk
returns normally, that is the return value ofcatch
.Handler is invoked outside the scope of its own
catch
. Ifhandler
again throws to the same key, a new handler from further up the call chain is invoked.If the key is
#t
, then a throw to any symbol will match this call tocatch
.
Function: throw
key
&rest
args
...
Invoke the catch form matching
key
, passingargs
to thehandler
.If the key is a symbol it will match catches of the same symbol or of #t.
If there is no handler at all, an error is signaled.
procedure: error
message
args
...
Raise an error with key
misc-error
and a message constructed by displayingmsg
and writingargs
. This normally prints a stack trace, and brings you back to the top level, or exits kawa if you are not running interactively. This procedure is part of SRFI-23, and other Scheme implementations.
Function: primitive-throw
exception
Throws the
exception
, which must be an instance of a sub-class of<java.lang.Throwable>
.
Syntax: try-finally
body
handler
Evaluate
body
, and return its result. However, before it returns, evaluatehandler
. Even ifbody
returns abnormally (by throwing an exception),handler
is evaluated.(This is implemented just like Java's
try
-finally
.)
Syntax: try-catch
body
handler
...
Evaluate
body
, in the context of the givenhandler
specifications. Eachhandler
has the form:var
type
exp
...If an exception is thrown in
body
, the firsthandler
is selected such that the thrown exception is an instance of thehandler
'stype
. If nohandler
is selected, the exception is propagated through the dynamic execution context until a matchinghandler
is found. (If no matchinghandler
is found, then an error message is printed, and the computation terminated.)Once a
handler
is selected, thevar
is bound to the thrown exception, and theexp
in thehandler
are executed. The result of thetry-catch
is the result ofbody
if no exception is thrown, or the value of the lastexp
in the selectedhandler
if an exception is thrown.(This is implemented just like Java's
try
-catch
.)
Function: dynamic-wind
in-guard
thunk
out-guard
All three arguments must be 0-argument procedures. First calls
in-guard
, thenthunk
, thenout-guard
. The result of the expression is that ofthunk
. Ifthunk
is exited abnormally (by throwing an exception or invoking a continuation),out-guard
is called.If the continuation of the dynamic-wind is re-entered (which is not yet possible in Kawa), the
in-guard
is called again.This function was added in R5RS.