Back to index

plt-scheme  4.2.1
Functions | Variables
catch.c File Reference
#include "escheme.h"

Go to the source code of this file.

Functions

static void init_exn_catching_apply ()
Scheme_Object_apply_thunk_catch_exceptions (Scheme_Object *f, Scheme_Object **exn)
Scheme_Objectextract_exn_message (Scheme_Object *v)
static Scheme_Objectdo_eval (void *s, int noargc, Scheme_Object **noargv)
static Scheme_Objecteval_string_or_get_exn_message (char *s)
static Scheme_Objectcatch_eval_error (int argc, Scheme_Object **argv)
Scheme_Objectscheme_reload (Scheme_Env *env)
Scheme_Objectscheme_initialize (Scheme_Env *env)
Scheme_Objectscheme_module_name ()

Variables

static Scheme_Objectexn_catching_apply
static Scheme_Objectexn_p
static Scheme_Objectexn_message

Function Documentation

Definition at line 54 of file catch.c.

{
  Scheme_Object *v;

  init_exn_catching_apply();
  
  v = _scheme_apply(exn_catching_apply, 1, &f);
  /* v is a pair: (cons #t value) or (cons #f exn) */

  if (SCHEME_TRUEP(SCHEME_CAR(v)))
    return SCHEME_CDR(v);
  else {
    *exn = SCHEME_CDR(v);
    return NULL;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Scheme_Object* catch_eval_error ( int  argc,
Scheme_Object **  argv 
) [static]

Definition at line 108 of file catch.c.

{
  Scheme_Object *bs;

  if (!SCHEME_CHAR_STRINGP(argv[0]))
    scheme_wrong_type("eval-string/catch-error", "string", 0, argc, argv);

  bs = scheme_char_string_to_byte_string(argv[0]);
  
  return eval_string_or_get_exn_message(SCHEME_BYTE_STR_VAL(bs));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Scheme_Object* do_eval ( void s,
int  noargc,
Scheme_Object **  noargv 
) [static]

Definition at line 85 of file catch.c.

{
  return scheme_eval_string((char *)s, scheme_get_env(NULL));
}

Here is the caller graph for this function:

static Scheme_Object* eval_string_or_get_exn_message ( char *  s) [static]

Definition at line 90 of file catch.c.

{
  Scheme_Object *v, *exn;

  v = _apply_thunk_catch_exceptions(scheme_make_closed_prim(do_eval, s), &exn);
  /* Got a value? */
  if (v)
    return v;

  v = extract_exn_message(exn);
  /* Got an exn? */
  if (v)
    return v;

  /* `raise' was called on some arbitrary value */
  return exn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 71 of file catch.c.

{
  init_exn_catching_apply();

  if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
    return _scheme_apply(exn_message, 1, &v);
  else
    return NULL; /* Not an exn structure */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_exn_catching_apply ( ) [static]

Definition at line 29 of file catch.c.

{
  if (!exn_catching_apply) {
    Scheme_Env *env;
    char *e = 
      "(lambda (thunk) "
       "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
         "(cons #t (thunk))))";

    /* make sure we have a namespace with the standard bindings: */
    env = (Scheme_Env *)scheme_make_namespace(0, NULL);

    scheme_register_extension_global(&exn_catching_apply, sizeof(Scheme_Object *));
    scheme_register_extension_global(&exn_p, sizeof(Scheme_Object *));
    scheme_register_extension_global(&exn_message, sizeof(Scheme_Object *));
    
    exn_catching_apply = scheme_eval_string(e, env);
    exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env);
    exn_message = scheme_lookup_global(scheme_intern_symbol("exn-message"), env);
  }
}

Here is the caller graph for this function:

Definition at line 135 of file catch.c.

{
  /* First load is same as every load: */
  return scheme_reload(env);
}

Here is the call graph for this function:

Definition at line 141 of file catch.c.

{
  /* This extension doesn't define a module: */
  return scheme_false;
}

Definition at line 124 of file catch.c.

{
  scheme_add_global("eval-string/catch-error",
                  scheme_make_prim_w_arity(catch_eval_error,
                                        "eval-string/catch-error", 
                                        1, 1),
                  env);

  return scheme_void;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 27 of file catch.c.

Definition at line 27 of file catch.c.

Scheme_Object * exn_p [static]

Definition at line 27 of file catch.c.