Juan Reynoso Elias
En 2016-06-22 11:23:29
Handler-case

The handler function can then choose whether to handle the condition. The function can decline to handle the condition by simply returning normally, in which case control returns to the SIGNAL function, which will search for the next most recently established handler with a compatible type specifier. To handle the condition, the function must transfer control out of SIGNAL via a nonlocal exit.

Handler case
 
 (defun divide (x y)
  "This function divide x y"
  (let ((result nil))
    (handler-case
    (progn
      (setf result (/ x y))
      (format t "The result is: ~a~%" result))
      ;; the error
      (division-by-zero ()
    (format t "There is an error")))))
 
CL-USER> (divide 8 2)
The result is: 4

 CL-USER> (divide 8 0)
There is an error

#lisp
 
También te podría interesar