This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
Re[1]: Catching an error
- To: aguillem@ens-lyon.fr
- Subject: Re[1]: Catching an error
- From: "Eric M. Ludlam" <zappo@ultranet.com>
- Date: Fri, 21 May 1999 16:13:04 -0400
- CC: guile@cygnus.com
- References: <199905211901.VAA23047@piment.ens-lyon.fr>
- Reply-to: zappo@ultranet.com
>>> Alexandre Guillemet <aguillem@ens-lyon.fr> seems to think that:
>Hello
>
>I work with the 1.2 version of guile.
>I don't know to use the function : gh_eval_str_with_catch
>What is exactly the type scm_catch_handler_t ?
>I need to catch the error provide by an syntaxic error in a C string.
>There's nothing about it in the tutorial and other docs I found.
[ ... ]
If I recall correctly the function gh_eval_str_with_catch does not
work as advertised (or not advertised in this case) in 1.2. You can
get the same behavior with the attached code snippet. "catcher" is a
function to run when there is an error. cs_eval_str is the function
you call with a C string.
The output of catcher is my own devising, and isn't as helpful as I'd
necessarily like. Also, you don't have to use the stack version of
the catch routine. I just happen to like stack traces. :)
Eric
---------
static SCM catcher(void *data, SCM tag, SCM throw_args)
{
SCM tmp;
SCM the_stack;
SCM port = scm_current_output_port(); /* set this to whatever */
/* Throw args seem to be: ( FN FORMAT ARGS #f )
*/
scm_puts("Function: ", port);
scm_display(gh_car(throw_args), port);
scm_puts(", ", port);
scm_display(tag, port);
scm_newline(port);
tmp = gh_cadr(throw_args);
if(gh_string_p(tmp))
{
scm_puts("Error: ", port);
scm_display_error_message(tmp, gh_caddr(throw_args), port);
}
scm_puts("Other Data: ", port);
scm_display(gh_car(gh_cdddr(throw_args)), port);
scm_newline(port);
scm_newline(port);
the_stack = scm_fluid_ref(SCM_CDR(scm_the_last_stack_fluid));
if(SCM_NFALSEP(the_stack))
{
scm_display_backtrace(the_stack, port, SCM_UNDEFINED, SCM_UNDEFINED);
}
return gh_int2scm(1);
}
void cs_eval_str(char *str)
{
scm_internal_stack_catch (SCM_BOOL_T, (scm_catch_body_t) gh_eval_str, str,
(scm_catch_handler_t) catcher, str);
}