[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Error Handling



(I couldn't mail to you, so I'm posting. It may be of general interest anyway.)


I have a function EVAL-WITHOUT-ERROR that does something similar. All errors
resulting from the evaluation of the form are caught. You may be able to adapt
it to your needs. It works by rebinding the definition of the function
SI:UNIVERSAL-ERROR-HANDLER. The macro PROGN-WITHOUT-ERROR is similar.

I don't think there's a portable way to do this. I.e., one that does not
require knowledge of internal system facilities.


(defun eval-without-error (form)
  (let ((hold-universal-error-handler
         (symbol-function 'si::universal-error-handler))
        result)
    (unwind-protect
        (progn
          (setf (symbol-function 'si::universal-error-handler)
                (symbol-function 'our-universal-error-handler))
          (setq result
                (catch 'my-quit-tag
                  (eval form))))
      (setf (symbol-function 'si::universal-error-handler)
            hold-universal-error-handler))
    result))


(defmacro progn-without-error (&body body)
  `(eval-without-error '(progn ,@body)))


(defun our-universal-error-handler (&rest everything)
  (format t "An error: ~S ~%" everything)
  (throw 'my-quit-tag :error))


-- David Cogen