[plt-scheme] Code for catching exceptions in embedding applications
Hi,
While trying to migrate an application to PLT 4.1, I stuck with
exception handling.
Code below (basically it has been extracted from PLT documentation)
crashes with
#f::0: compile: bad syntax; function application is not allowed, because
no #%app syntax transformer is bound in: (lambda (thunk) (with-handlers
((void (lambda(exn) (cons #f exn)))) (cons #t (thunk))))
Seg fault (internal error) at 4
Do I need to `require' some module for this to work?
#define MZ_PRECISE_GC 1
#include <scheme.h>
/* #include "base.c" */
static Scheme_Env *environment = NULL;
static int
scheme_main(void *data)
{
char *e =
"(lambda (thunk) "
"(with-handlers ([void (lambda (exn) (cons #f exn))]) "
"(cons #t (thunk))))";
Scheme_Env *env = NULL;
Scheme_Object *exn_catching_apply = NULL;
Scheme_Object *sym = NULL;
MZ_GC_DECL_REG(3);
MZ_GC_VAR_IN_REG(0, env);
MZ_GC_VAR_IN_REG(1, exn_catching_apply);
MZ_GC_VAR_IN_REG(2, sym);
MZ_GC_REG();
MZ_REGISTER_STATIC(environment);
environment = scheme_basic_env();
/* declare_modules(environment);
sym = scheme_intern_symbol("scheme/base");
scheme_namespace_require(sym);
*/
env = (Scheme_Env *)scheme_make_namespace(0, NULL);
exn_catching_apply = scheme_eval_string(e, env);
MZ_GC_UNREG();
return 1;
}
int main()
{
return scheme_main_stack_setup(1, scheme_main, NULL);
}