Question: ignore-error on Common Lisp

Question

ignore-error on Common Lisp

Answers 1
Added at 2016-12-30 10:12
Tags
Question

I'm trying to handle errors in Common Lisp easily, but I have some problems.

In particular, I have this function.

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

I just want that if some conditions fail into the

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

it's shown the error message, otherwise just

T

How can I do? There is a better way to handle this type of errors? I looking for something very simple.

Someone can do an example showing how to use ignore-error?

Thank you.

Answers to

ignore-error on Common Lisp

nr: #1 dodano: 2016-12-30 11:12

You can use 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).
Source Show
◀ Wstecz