[previous] [up] [next]     [contents] [index]
Next: Temporarily Catching Error Escapes Up: MzScheme Architecture Previous: Library Functions

Exceptions and Escape Continuations

When MzScheme encounters an error, it raises an exception. The default exception handler invokes the error display handler and then the error escape handler. The default error escape handler escapes via a primitive error escape, which is implemented by calling scheme_longjmp(scheme_error_buf). An embedding program should call scheme_setjmp(scheme_error_buf) before any top-level entry into MzScheme evaluation to catch primitive error escapes:

  ...
  if (scheme_setjmp(scheme_error_buf)) {
    /* There was an error */
    ...
  } else {
    v = scheme_eval_string(s, env);
  }
  ...

New primitive procedures can raise a generic exception by calling scheme_signal_error. The parameters for scheme_signal_error are the same as for the standard C function printf. A specific primitive exception can be raised by calling scheme_raise_exn.

Full continuations are implemented in MzScheme by copying the C stack and using scheme_setjmp and scheme_longjmp. As long a C/C++ application invokes MzScheme evaluation through the top-level evaluation functions (scheme_eval, scheme_eval, etc., as opposed to _scheme_eval, _scheme_apply, etc.), the code is protected against any unusual behavior from Scheme evaluations (such as returning twice from a function) because continuation invocations ae confined to jumps within a single top-level evaluation. However, escape continuation jumps are still allowed; as explained in the following sub-section, special care must be taken in extension that is sensitive to escapes.





PLT