[plt-scheme] Seeking advice with error handling of an exception...

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Mar 1 09:31:58 EST 2006

At Tue, 28 Feb 2006 19:32:29 -0800 (PST), Harley Gorrell wrote:
>     The problem occurs when an error is thrown from within
> scheme.  The first error appears to be handled correctly,
> but the second causes a core dump. 

I think the problem is that "Inside MzScheme" had out-of-date
information on catching errors (until I fixed it in the nightly builds
about a week ago).

Instead of something like

   if (scheme_setjmp(scheme_error_buf)) {
     ...
   }

you now need to write

  mz_jmp_buf * volatile save, fresh;
  ...
  save = scheme_current_thread->error_buf;
  scheme_current_thread->error_buf = &fresh;
  if (scheme_setjmp(scheme_error_buf)) {
    /* There was an error */
    scheme_current_thread->error_buf = save;
    ...
  } else {
    v = scheme_eval_string(s, env);
    scheme_current_thread->error_buf = save;
  }
  ...

In other words, instead of overwriting the current jmpbuf, install a
fresh one, and then restore the old one when escaping of finishing.

Matthew



Posted on the users mailing list.