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

Re: handler-case problem?



This one should certainly go into a MCL FAQ.
Almost everyone got bite by this one at one time or another.

<---
| So when I enter this form I get this behavior:
| ? (handler-case (/ pi 0) (DIVISION-BY-ZERO (x) (print x)))
| > Error: While compiling an anonymous function :
| >        Error: "Can't divide by zero." 
| >        signalled during compile-time evaluation of (/ 3.141592653589793 0) .
| > Type Command-. to abort.
| See the RestartsI menu item for further choices.
| 1 > (local 7)
| #<DIVISION-BY-ZERO #x1924C49>
| 1 > (type-of (local 7))
| DIVISION-BY-ZERO
| 1 > 
| Aborted
| ? 
| 
| Am I doing something wrong or is handler-case used-up?
| Thanks.
--->

The problem is that the error occurs during compilation. The compiler
recognizes 0 as a constant and sees that a division by zero must occur
and so saves you from the error occuring at runtime.

Try the following:

(let ((x 0))
  (handler-case (/ pi x) (DIVISION-BY-ZERO (x) (print x))))

Guillaume.

*********************************************************************
* Guillaume Cartier                 (514) 844-5294 (maison)         *
* L.A.C.I.M.                        (514) 987-4290 (bureau)         *
* Universite du Quebec a Montreal   (514) 987-8477 (telecopieur)    *
* Montreal, Quebec, Canada          cartier@math.uqam.ca (internet) *
*********************************************************************