Function: handler-bind-1

handler-bind-1 is a function defined in eval.c.

Signature

(handler-bind-1 BODYFUN [CONDITIONS HANDLER]...)

Documentation

Set up error handlers around execution of BODYFUN.

BODYFUN should be a function and it is called with no arguments. CONDITIONS should be a list of condition names (symbols). When an error is signaled during execution of BODYFUN, if that error matches one of CONDITIONS, then the associated HANDLER is called with the error as argument. HANDLER should either transfer the control via a non-local exit, or return normally. If it returns normally, the search for an error handler continues from where it left off.

Source Code

// Defined in /usr/src/emacs/src/eval.c
{
  eassert (nargs >= 1);
  Lisp_Object bodyfun = args[0];
  int count = 0;
  if (nargs % 2 == 0)
    error ("Trailing CONDITIONS without HANDLER in `handler-bind`");
  for (ptrdiff_t i = nargs - 2; i > 0; i -= 2)
    {
      Lisp_Object conditions = args[i], handler = args[i + 1];
      if (NILP (conditions))
        continue;
      push_handler_bind (conditions, handler, count++);
    }
  Lisp_Object ret = call0 (bodyfun);
  for (; count > 0; count--)
    pop_handler ();
  return ret;
}