home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / mcl / 1624 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  1.8 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!cartier@math.uqam.ca
  2. From: cartier@math.uqam.ca (Guillaume Cartier)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: handler-case problem?
  5. Message-ID: <9211182026.AA15140@mipsmath.math.uqam.ca>
  6. Date: 18 Nov 92 20:26:08 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 40
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. This one should certainly go into a MCL FAQ.
  12. Almost everyone got bite by this one at one time or another.
  13.  
  14. <---
  15. | So when I enter this form I get this behavior:
  16. | ? (handler-case (/ pi 0) (DIVISION-BY-ZERO (x) (print x)))
  17. | > Error: While compiling an anonymous function :
  18. | >        Error: "Can't divide by zero." 
  19. | >        signalled during compile-time evaluation of (/ 3.141592653589793 0) .
  20. | > Type Command-. to abort.
  21. | See the RestartsI menu item for further choices.
  22. | 1 > (local 7)
  23. | #<DIVISION-BY-ZERO #x1924C49>
  24. | 1 > (type-of (local 7))
  25. | DIVISION-BY-ZERO
  26. | 1 > 
  27. | Aborted
  28. | ? 
  29. | Am I doing something wrong or is handler-case used-up?
  30. | Thanks.
  31. --->
  32.  
  33. The problem is that the error occurs during compilation. The compiler
  34. recognizes 0 as a constant and sees that a division by zero must occur
  35. and so saves you from the error occuring at runtime.
  36.  
  37. Try the following:
  38.  
  39. (let ((x 0))
  40.   (handler-case (/ pi x) (DIVISION-BY-ZERO (x) (print x))))
  41.  
  42. Guillaume.
  43.  
  44. *********************************************************************
  45. * Guillaume Cartier                 (514) 844-5294 (maison)         *
  46. * L.A.C.I.M.                        (514) 987-4290 (bureau)         *
  47. * Universite du Quebec a Montreal   (514) 987-8477 (telecopieur)    *
  48. * Montreal, Quebec, Canada          cartier@math.uqam.ca (internet) *
  49. *********************************************************************
  50.