From: Michael Park
Subject: recovering from errors gracefully
Date: 
Message-ID: <ff20888b.0305190532.71d713f0@posting.google.com>
I'm looking for something like

try {
  // ...
}
catch (...) {
   // do something else altogether
   // don't care about the stack
}

that would catch all errors, including type errors, out-of-bounds,
division by zero and the rest. I read about handler-* functions, but
it looks like they don't do what I want.

From: Brian Downing
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <Du5ya.31309$rt6.12575@sccrnsc02>
In article <····························@posting.google.com>,
Michael Park <···········@whoever.com> wrote:
> I'm looking for something like
> 
> try {
>   // ...
> }
> catch (...) {
>    // do something else altogether
>    // don't care about the stack
> }
> 
> that would catch all errors, including type errors, out-of-bounds,
> division by zero and the rest. I read about handler-* functions, but
> it looks like they don't do what I want.

I think handler-case is really what you're looking for.  It can trap
all the errors above and run stuff after the stack is unwound.

(defmacro with-punting (form)
  `(handler-case ,form
     (error (condition)
       (format t "~&Well, we got a ~S condition, but we're punting:~&~A~%~%"
               condition condition))))

(defun test-punting ()
  (with-punting (car 42))
  (with-punting (elt (make-array 5) 42))
  (with-punting (/ 42 0)))

* (test-punting)
Well, we got a #<TYPE-ERROR {4806D525}> condition, but we're punting:
Type-error in KERNEL::OBJECT-NOT-LIST-ERROR-HANDLER:  42 is not of type LIST

Well, we got a #<COMMON-LISP::INDEX-TOO-LARGE-ERROR {4806E2F5}> condition, but we're punting:
Error in COMMON-LISP::SIGNAL-INDEX-TOO-LARGE-ERROR: 42: Index too large.

Well, we got a #<DIVISION-BY-ZERO {4806FD85}> condition, but we're punting:
Arithmetic error DIVISION-BY-ZERO signalled.
Operation was KERNEL::DIVISION, operands (42 0).

NIL

You could probably make some sort of with-try-catch macro to simulate
the above structure, but that might be considered in bad Lisp form, I
don't know.

-bcd
--
(format nil "~:(~{~A ~}~)~(<····@·@{~A~#[~:;.~]~}~}>~)"
        '(brian downing) '(bdowning lavos net))
From: Franz Kafka
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <oL5ya.7845$ef3.6157@news01.roc.ny.frontiernet.net>
"Michael Park" <···········@whoever.com> wrote in message
·································@posting.google.com...
> I'm looking for something like
>
> try {
>   // ...
> }
> catch (...) {
>    // do something else altogether
>    // don't care about the stack
> }
>
> that would catch all errors, including type errors, out-of-bounds,
> division by zero and the rest. I read about handler-* functions, but
> it looks like they don't do what I want.

handler-case works by traping certain errors like math errors
so if someone puts a string into a math function it will still
generate an error, but a division by zero won't.

ignore-errors does exactly what it says. it evaluates a
form and will ignore any errors that it encounters.

(ignore-errors ...) ;; Does not crash for errors.

BTW, I never had to use handler-case or ignore-errors maybe
someone else here will tell you more about what they do.
From: Tim Bradshaw
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <ey3u1brrng1.fsf@cley.com>
* Franz Kafka wrote:
> handler-case works by traping certain errors like math errors
> so if someone puts a string into a math function it will still
> generate an error, but a division by zero won't.

HANDLER-CASE can handle any class of error (or in fact any condition
at all).

(handler-case
  (/ a b)
 (t (x)
  ...))

--tim
From: Espen Vestre
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <kwznljyo4k.fsf@merced.netfonds.no>
"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com> writes:

> handler-case works by traping certain errors like math errors
> so if someone puts a string into a math function it will still
> generate an error, but a division by zero won't.
> 
> ignore-errors does exactly what it says. it evaluates a
> form and will ignore any errors that it encounters.

This is confusing advice, ignore-errors doesn't trap any more errors
than (handler-case form (error (cond) ...)) does (in fact, this is
explicitly stated in the standard).
-- 
  (espen)
From: Brian Downing
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <LS6ya.657226$Zo.140239@sccrnsc03>
In article <··············@merced.netfonds.no>,
Espen Vestre  <·····@*do-not-spam-me*.vestre.net> wrote:
> This is confusing advice, ignore-errors doesn't trap any more errors
> than (handler-case form (error (cond) ...)) does (in fact, this is
> explicitly stated in the standard).

In fact, IGNORE-ERRORS is implemented as

(defmacro ignore-errors (&rest forms)
  `(handler-case (progn ,@forms)
     (error (condition) (values nil condition))))

on SBCL (the only Lisp for which I have the source convenient).

-bcd
--
(format nil "~:(~{~A ~}~)~(<····@·@{~A~#[~:;.~]~}~}>~)"
        '(brian downing) '(bdowning lavos net))
From: Coby Beck
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <babkip$2vpu$1@otis.netspace.net.au>
"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com>
wrote in message ························@news01.roc.ny.frontiernet.net...
> handler-case works by traping certain errors like math errors
> so if someone puts a string into a math function it will still
> generate an error, but a division by zero won't.

handler-case has no bearing whatsoever on what errors are generated.  It
will handle all errors of any type or subtype that you write into it.  If
you have no handler for the type of error that happens the error propogates
past to higher level code.


> ignore-errors does exactly what it says. it evaluates a
> form and will ignore any errors that it encounters.
>
> (ignore-errors ...) ;; Does not crash for errors.
>
> BTW, I never had to use handler-case or ignore-errors maybe
> someone else here will tell you more about what they do.

ignore-errors is tempting, but boy it can bite you very hard!  I don't think
I have ever used it well...

-- 
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Thomas A. Russ
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <ymiu1bnnbxj.fsf@sevak.isi.edu>
"Coby Beck" <·····@mercury.bc.ca> writes:
> 
> ignore-errors is tempting, but boy it can bite you very hard!  I don't think
> I have ever used it well...

One application I found for it was testing to see if a logical host was
defined.  Since there isn't any standard call (that I know of) for
finding out if it is defined, you have to try to get the translations.
But if you ask for the translations of an undefined logical host, you
get an error, at least in Allegro CL.

So I end up wrapping an IGNORE-ERRORS around the call to see if there
are any defined translations (in order to otherwise set it to some
default value.)

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Tim Bradshaw
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <ey3r86rzp7p.fsf@cley.com>
* Thomas A Russ wrote:

> One application I found for it was testing to see if a logical host was
> defined.  Since there isn't any standard call (that I know of) for
> finding out if it is defined, you have to try to get the translations.
> But if you ask for the translations of an undefined logical host, you
> get an error, at least in Allegro CL.

Unless I'm missing something, this is a really serious omission in the
spec.  I have *lots* of bits of code which want to do `if the host x
is defined then do nothing, else define these translations', and I
resort to horrors like you describe.

--tim
From: Espen Vestre
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <kw8yt312cf.fsf@merced.netfonds.no>
···········@whoever.com (Michael Park) writes:

> division by zero and the rest. I read about handler-* functions, but
> it looks like they don't do what I want.

Read about handler-case again, I think it does what you want.

E.g.


CL-USER 37 > (handler-case (/ 1 0) 
               (error (cond) (format t "Silly me: ~a~%" cond)))
Silly me: Division-by-zero caused by / of (1 0).
NIL

-- 
  (espen)
From: Barry Margolin
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <h%6ya.5$sO4.1319@paloalto-snr1.gtei.net>
In article <····························@posting.google.com>,
Michael Park <···········@whoever.com> wrote:
>I'm looking for something like
>
>try {
>  // ...
>}
>catch (...) {
>   // do something else altogether
>   // don't care about the stack
>}
>
>that would catch all errors, including type errors, out-of-bounds,
>division by zero and the rest. I read about handler-* functions, but
>it looks like they don't do what I want.

(handler-case
    (progn ...)
  ((error ()
     ; do something else altogether
     ; don't care about the stack
   )))


-- 
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Sunil Mishra
Subject: Re: recovering from errors gracefully
Date: 
Message-ID: <t0mdnV_Qc5N3J0qjXTWc-g@speakeasy.net>
Others have talked about handler case, for completeness with respect to 
the try/catch forms in java you should also have a look at unwind-protect.

Sunil


Michael Park wrote:
> I'm looking for something like
> 
> try {
>   // ...
> }
> catch (...) {
>    // do something else altogether
>    // don't care about the stack
> }
> 
> that would catch all errors, including type errors, out-of-bounds,
> division by zero and the rest. I read about handler-* functions, but
> it looks like they don't do what I want.
From: Franz Kafka
Subject: Installing a CD Drive on a MacIvory ???
Date: 
Message-ID: <QHcCa.304$BK2.195@news01.roc.ny.frontiernet.net>
"I would like to install a CD drive onto a MacIvory rev. 2 running on the
Mac
IIfx--I have a thing for retro hardware hacking.

The Genera 8.3 command:
Show Machine Configuration
and the Mac 7.6.1 SCSI tools
show that it is device 2.

But when I stick a CD in the Mac Desktop does not show the CD.

& I don't know what commands in Genera 8.3 I'd have 2 give
to look at the contents of a CD, or to install CLIM, Joushua, and
other stuff from Genera.

I'd apreciate any help you could provide me with.

I'd love to hardware-hack a Symbolics board :)

yes, I know it's an old machine ;) so please don't waste bandwidth by
telling me that, I just want to learn about it, hack it, and explore it.

Thankz,

FK (published 1 technical article in a peer reviewed magazine--if you
consider 2600 located @ (www.2600.com) to be a peer reviewed magazine ;)

PS

Sorry I had 2 sneak it in like I just did--my newsreader was being stuborn.