This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Catching an error


To: zappo@ultranet.com
Cc: aguillem@ens-lyon.fr

Hi.

I found this message (see below) in the mail archive.  I tried the code
and it works great as-is.  However, I would like to capture the return
value of the gh_eval_str().  I tried changing cs_eval_str:

static SCM cs_eval_str(char *str)
{
  return(scm_internal_stack_catch (SCM_BOOL_T, (scm_catch_body_t) gh_eval_str, str,
                            (scm_catch_handler_t) catcher, str));
}

but this sometimes crashes (in some GC routine -- the C runtime stack gets
messed up so I can't track where exactly it is via gdb).

Is there a recommended procedure for this?

Thanks.

 > From: "Eric M. Ludlam" <zappo@ultranet.com>
 > Date: Fri  May 21,  4:13pm
 >
 > >>> 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);
 > }

-- 
Robert Brown                        |         Continuum Software, Inc.
Programmer                          | 800 West Cummings Park, Ste 4950
mailto:robertb@continuumsi.com      |            Woburn, MA 01801-6504
voice: 781-932-8400 x100            |                fax: 781-932-2558

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]