Previous: Throw and Catch, Up: Exceptions [Contents][Index]
The primary function to deal with Guile’s exceptions from C is
scm_c_catch.
scm_c_catch can register a C functions as a body thunk and
exception handler as opposed to scm_catch_with_pre_unwind_handler
and scm_catch which take Scheme procedures as body thunk and
handler arguments. scm_internal_catch is retained for backward
compatibility and is a specialization of scm_c_catch with the
pre-unwind handler and corresponding data set to NULL.
body is called as body (body_data) with a catch
on exceptions of the given tag type. If an exception is caught,
pre_unwind_handler and handler are called as
handler (handler_data, key, args).
key and args are the SCM key and argument list from
the throw.
body and handler should have the following prototypes.
scm_t_catch_body and scm_t_catch_handler are pointer
typedefs for these.
SCM body (void *data); SCM handler (void *data, SCM key, SCM args);
The body_data and handler_data parameters are passed to the respective calls so an application can communicate extra information to those functions.
If the data consists of an SCM object, care should be taken that
it isn’t garbage collected while still required. If the SCM is a
local C variable, one way to protect it is to pass a pointer to that
variable as the data parameter, since the C compiler will then know the
value must be held on the stack. Another way is to use
scm_remember_upto_here_1 (see Foreign Object Memory Management).
The above scm_with_throw_handler takes Scheme procedures as body
(thunk) and handler arguments. scm_c_with_throw_handler is an
equivalent taking C functions. See scm_c_catch
(see Exceptions and C) for a description of the parameters, the
behavior however of course follows with-throw-handler.
Previous: Throw and Catch, Up: Exceptions [Contents][Index]