This is the mail archive of the 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[1]: Catching an error

>>> Alexandre Guillemet <> seems to think that:
>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. :)


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);
  tmp = gh_cadr(throw_args);
      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);

  the_stack = scm_fluid_ref(SCM_CDR(scm_the_last_stack_fluid));

      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);

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