Subject: Re: catching floating point exceptions in lisp
From: Erik Naggum <clerik@naggum.no>
Date: 1997/10/10
Newsgroups: comp.lang.lisp
Message-ID: <3085446108962378@naggum.no>


* Stephen Dongjun Bay
| Occaisonally divide by zero errors occur and stops program execution.
| Instead of stoping my lisp program I would like to handle the divide by
| zero errors automatically (i.e. I can throw away the expressions because
| they are invalid) and continue.

if the expression is truly uninteresting when it contains such an error,
you can wrap the call to `eval' in an `ignore-errors' form.  the primary
value is then nil if an error occurred.  you may check the secondary value
for any condition that might have occurred.  otherwise, you might want to
consider setting up a handler for the condition `arithmetic-error'.  you
also gain access to the operands and the operation that caused this
condition.

    (handler-case (+ (/ 3 4) (/ 1 0))
      (arithmetic-error (x)
	(format t "~S bit the proverbial bullet"
		(cons (arithmetic-error-operation x)
		      (arithmetic-error-operands x)))))
 -| (/ 1 0) bit the proverbial bullet
 => nil

#\Erik
-- 
if you think this year is "97", _you_ are not "year 2000 compliant".

see http://www.naggum.no/emacs/ for Emacs-20-related material.