2.7 Conditions

2.7.1 C Reference

Macro: ECL_HANDLER_CASE

C macro for handler-case

Synopsis

ECL_HANDLER_CASE_BEGIN(env,names) {

} ECL_HANDLER_CASE(n,condition) { {

} ECL_HANDLER_CASE_END;

Description

ECL_HANDLER_CASE_BEGIN runs a block of C code with a set of error handlers bound to the names given by the list names. The subsequent ECL_HANDLER_CASE statements specify what to do when the n-th type of conditions is found, where n is an integer denoting the position of the name in the list names.

When a condition is signaled, ECL scans the list of signal handlers, looking for matches based on typep. If the match with the highest precedence belongs to the list names, ECL will perform a non-local transfer of control to the appropriate ECL_HANDLER_CASE, passing it a condition object as unique argument.

The following example shows how to establish a handler for error conditions. Note how the first value to ECL_HANDLER_CASE matches the position of the condition name in the list:

cl_object error = ecl_make_symbol("ERROR","CL");
ECL_HANDLER_CASE_BEGIN(the_env, ecl_list1(error)) {
   /* This form is evaluated with bound handlers */
   output = cl_eval(1, form);
} ECL_HANDLER_CASE(1, condition) {
   /* This code is executed when an error happens */
   /* We just return the error that took place */
   output = condition;
} ECL_HANDLER_CASE_END;
Macro: ECL_RESTART_CASE

C macro for restart-case

Synopsis

ECL_RESTART_CASE_BEGIN(env,names) {

} ECL_RESTART_CASE(n,args) { {

} ECL_RESTART_CASE_END;

Description

ECL_RESTART_CASE_BEGIN runs a block of C code with a set of restarts bound to the names given by the list names. The subsequent ECL_RESTART_CASE statements specify what to do when the n-th restart is invoked, where n is an integer denoting the position of the name in the list names.

When the restart is invoked, it can receive any number of arguments, which are grouped in a list and stored in a new variable created with the name args.

The following example shows how to establish an abort and a use-value restart. Note how the first value to ECL_RESTART_CASE matches the position of the restart name in the list:

cl_object abort = ecl_make_symbol("ABORT","CL");
cl_object use_value = ecl_make_symbol("USE-VALUE","CL");
ECL_RESTART_CASE_BEGIN(the_env, cl_list(2, abort, use_value)) {
   /* This form is evaluated with bound restarts */
   output = cl_eval(1, form);
} ECL_RESTART_CASE(1, args) {
   /* This code is executed when the 1st restart (ABORT) is invoked */
   output = ECL_NIL;
} ECL_RESTART_CASE(2, args) {
   /* This code is executed when the 2nd restart (USE-VALUE) is invoked */
   output = ECL_CAR(args);
} ECL_RESTART_CASE_END;

2.7.1.1 ANSI dictionary

Common Lisp and C equivalence

Lisp symbolC function
abortcl_object cl_abort(cl_narg narg, ...)
break[Only in Common Lisp]
cell-error-name[Only in Common Lisp]
cerrorcl_object cl_cerror(cl_narg narg, cl_object continue_format_control, cl_object datum, ...)
compute-restartscl_object cl_compute_restarts(cl_narg narg, ...)
continuecl_object cl_continue(cl_narg narg, ...)
errorcl_object cl_error(cl_narg narg, cl_object datum, ...)
find-restartcl_object cl_find_restart(cl_narg narg, cl_object identifier, ...)
handler-caseECL_HANDLER_CASE macro
invalid-method-errorcl_object cl_invalid_method_error (cl_narg narg, cl_object method, cl_object format, ...)
invoke-debugger[Only in Common Lisp]
invoke-restartcl_object cl_invoke_restart(cl_narg narg, cl_object restart, ...)
invoke-restart-interactivelycl_object cl_invoke_restart_interactively(cl_object restart)
make-conditioncl_make_condition(cl_narg narg, cl_object type, ...)
method-combination-errorcl_object cl_method_combination_error(cl_narg narg, cl_object format, ...)
muffle-warningcl_object cl_muffle_warning(cl_narg narg, ...)
restart-name[Only in Common Lisp]
restart-caseECL_RESTART_CASE macro
signal[Only in Common Lisp]
simple-condition-format-control[Only in Common Lisp]
simple-condition-format-arguments[Only in Common Lisp]
store-valuecl_object cl_store_value(cl_narg narg, ...)
use-valuecl_object cl_use_value(cl_narg narg, ...)
warn[Only in Common Lisp]