From: Jonathon McKitrick
Subject: Understanding conditions/handlers
Date: 
Message-ID: <1154810583.689072.89900@i42g2000cwa.googlegroups.com>
I'm starting to get the whole concept through my thick head.  After
reading PCL and the chapter on Conditions from CLtL, I've made
progress.  I have a few questions, though.

1.  Right now, I can see how to apply handler-case for low-level error
recovery without a lot of extra flexibility.  And I can see how to use
handler-bind with restart-case for separating error recovery from
condition handling.  But I don't see how to use the others that are
available, like restart-bind.

2.  Related to number 1, are handler-case and handler-bind/restart case
pretty much the 'meat and potatoes' of error handling?  It seems from
CLtL that the other condition handling functions are mostly for
debuggers and/or REPL handling of errors.  Is this correct?

3.  How do you handle several forms to be called within one
restart-case in such a way that a condition can be handled but return
to execution of the others within the restart-case?  Or is it best to
just split the restart-case in 2?

From: Jonathon McKitrick
Subject: Re: Understanding conditions/handlers addendum
Date: 
Message-ID: <1154812479.474693.268090@n13g2000cwa.googlegroups.com>
Also, here's another issue I ran into:

When I use handler-bind with restart-case, the restart does not know
that the argument it is passed is a condition.

So, while this works:

(ignore-shutdown-condition (c) (format t "~%; --> Ignoring db error:
(~A ~A)~%" (type-of c) c))

the compiler chokes on this:

(ignore-shutdown-condition (c) (format t "~%; --> Ignoring db error:
(~A ~A)~%" (text c) c))

because it doesn't recognize 'c' as a condition with reader 'text'.  Is
there a better way here?
From: Barry Margolin
Subject: Re: Understanding conditions/handlers addendum
Date: 
Message-ID: <barmar-A35580.22184205082006@comcast.dca.giganews.com>
In article <························@n13g2000cwa.googlegroups.com>,
 "Jonathon McKitrick" <···········@bigfoot.com> wrote:

> Also, here's another issue I ran into:
> 
> When I use handler-bind with restart-case, the restart does not know
> that the argument it is passed is a condition.
> 
> So, while this works:
> 
> (ignore-shutdown-condition (c) (format t "~%; --> Ignoring db error:
> (~A ~A)~%" (type-of c) c))
> 
> the compiler chokes on this:
> 
> (ignore-shutdown-condition (c) (format t "~%; --> Ignoring db error:
> (~A ~A)~%" (text c) c))
> 
> because it doesn't recognize 'c' as a condition with reader 'text'.  Is
> there a better way here?

I don't understand why this would prevent compilation.  Common Lisp 
doesn't require compile-time type analysis.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Barry Margolin
Subject: Re: Understanding conditions/handlers
Date: 
Message-ID: <barmar-E2EDFA.22123705082006@comcast.dca.giganews.com>
In article <·······················@i42g2000cwa.googlegroups.com>,
 "Jonathon McKitrick" <···········@bigfoot.com> wrote:

You keep starting duplicate threads: 3 about Norvig's macro comment, and 
2 about this.  I've noticed in the past few months that whenever someone 
posts a duplicate message, it's almost always someone using Google 
Groups instead of a real newsreader; does Google make it hard for you to 
tell if a post was successful?

> I'm starting to get the whole concept through my thick head.  After
> reading PCL and the chapter on Conditions from CLtL, I've made
> progress.  I have a few questions, though.
> 
> 1.  Right now, I can see how to apply handler-case for low-level error
> recovery without a lot of extra flexibility.  And I can see how to use
> handler-bind with restart-case for separating error recovery from
> condition handling.  But I don't see how to use the others that are
> available, like restart-bind.

restart-bind is a lower-level interface, mainly useful for restart-case 
to expand into.  It may also be useful for programmers who need more 
control and flexibility than restart-case provides.

> 2.  Related to number 1, are handler-case and handler-bind/restart case
> pretty much the 'meat and potatoes' of error handling?  It seems from
> CLtL that the other condition handling functions are mostly for
> debuggers and/or REPL handling of errors.  Is this correct?

Which other functions are you referring to?  IGNORE-ERRORS is a simple 
interface that many applications use.

> 3.  How do you handle several forms to be called within one
> restart-case in such a way that a condition can be handled but return
> to execution of the others within the restart-case?  Or is it best to
> just split the restart-case in 2?

You need to put a RESTART-CASE around each expression.  A macro would be 
good for this:

(defmacro progn-restarting ((&rest restarts) &body forms)
  `(progn ,@(loop for form in forms
                  collect `(restart-case ,form ,restarts))))

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***