Subject: Re: newbie exception handling question
From: Erik Naggum <>
Date: Mon, 10 Sep 2001 09:36:50 GMT
Newsgroups: comp.lang.lisp
Message-ID: <>

* Donna <>
> of course this will produce an error/exception and that is what I want to 
> catch and handle gracefully, basically by giving this program a bad score 
> and exiting from the fitness function.

  If you wrap the entire function body in an ignore-errors form, it will
  terminate upon encountering any errors at all and return two values: a
  nil primary value and the error object as the secondary value, which you
  are free to ignore, as well.  This is a quick and painless exit from a
  function with an error with the added bonus of returning "false".  If you
  need more scoring "resolution" than that, perhaps the calling function
  can take care of it?

> Now I could write functions like  newrest, newfirst, etc and handle the
> case when the argument is not a list,  then when I find the best fit
> program change newrest to rest, etc. But that  seems awkward to me. I
> would really rather do something more elegant. I  would welcome any
> suggestions, ideas, and comments.

  Common Lisp has a "safe mode" where all errors must be signalled.  It
  should be the default in your environment, but can be obtained with

(declaim (optimize (safety 3)))

  In my experience, this is where implementations differ the most in
  conforming, so it is hard to trust this requirement without talking to
  other users of the same implementation.  However, if you have more
  knowledge than the system can intuit from what you are attempting to do,
  you could write your own evaluator and examine this knowledge for
  consistency before you get any errors..  This is not as hard as it seems.