[plt-scheme] Code for catching exceptions in embedding applications

From: Sergey Khorev (sergey.khorev at gmail.com)
Date: Sat Oct 4 11:02:42 EDT 2008


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_VAR_IN_REG(0, env);
     MZ_GC_VAR_IN_REG(1, exn_catching_apply);
     MZ_GC_VAR_IN_REG(2, sym);


     environment = scheme_basic_env();
/*    declare_modules(environment);
     sym = scheme_intern_symbol("scheme/base");

     env = (Scheme_Env *)scheme_make_namespace(0, NULL);
     exn_catching_apply = scheme_eval_string(e, env);


     return 1;

int main()
     return scheme_main_stack_setup(1, scheme_main, NULL);

Posted on the users mailing list.