Common Lisp 上的忽略错误

ignore-error on Common Lisp

我正在尝试轻松处理 Common Lisp 中的错误,但我遇到了一些问题。

特别是我有这个功能

(defun function1 (m)
 (ignore-errors (and (condition-1) (condition-2))
   (format t "Error message")))

我只想在某些条件失败时进入

(and (condition-1) (condition-2)) 

显示错误消息,否则只是

T

我该怎么办? 有更好的方法来处理此类错误吗?我正在寻找非常简单的东西。

谁能举个例子说明如何使用 ignore-error?

谢谢。

您可以使用HANDLER-CASE

CL-USER 101 > (handler-case (and (evenp 2)
                                 (oddp 1))
               (error (c)
                 (princ c)
                 (values)))
T

CL-USER 102 > (handler-case (and (evenp 2)
                                 (/ 3 0)
                                 (oddp 1))
               (error (c)
                 (princ c)
                 (values)))
Division-by-zero caused by / of (3 0).