Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
catching floating point exceptions in lisp
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Barry Margolin  
View profile  
 More options Oct 9 1997, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1997/10/09
Subject: Re: catching floating point exceptions in lisp

In article <343D4E78.5...@ics.uci.edu>,
Stephen Dongjun Bay  <s...@ics.uci.edu> wrote:

>Does anybody know how to catch floating point exceptions in Lisp?

See the chapter of CLtL2 on the Condition System.  You can establish a
handler for ARITHMETIC-ERROR, DIVIDE-BY-ZERO, FLOATING-POINT-OVERFLOW,
and/or FLOATING-POINT-UNDERFLOW.

Or if you just want the expression to return NIL if it gets an error, use
the IGNORE-ERRORS macro.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Oct 10 1997, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <cle...@naggum.no>
Date: 1997/10/10
Subject: Re: catching floating point exceptions in lisp

* 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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »