From: Karol Skocik
Subject: how to print message coming from (error "...")
Date: 
Message-ID: <1183049901.111976.323880@c77g2000hse.googlegroups.com>
Hi,
  I have a piece of code which I can reduce to something like this:

(handler-case (some-form-causing-error)
          (error (condition)
            (... here I want to print the message from errror)
            nil))

so that when in the some-form-causing-error I call (error "xxx")
I want to print "xxx" in the part catching the condition.

Normally I make my own conditions but for simple prototyping I use
just error with string.

Any ideas?

Thanks,
  Karol

From: Richard M Kreuter
Subject: Re: how to print message coming from (error "...")
Date: 
Message-ID: <87ved8q7tc.fsf@tan-ru.localdomain>
Karol Skocik <············@gmail.com> writes:

>   I have a piece of code which I can reduce to something like this:
>
> (handler-case (some-form-causing-error)
>           (error (condition)
>             (... here I want to print the message from errror)
>             nil))
>
> so that when in the some-form-causing-error I call (error "xxx")
> I want to print "xxx" in the part catching the condition.
>
> Normally I make my own conditions but for simple prototyping I use
> just error with string.
>
> Any ideas?


(format t "~&~A~&" condition)

--
RmK
From: Karol Skocik
Subject: Re: how to print message coming from (error "...")
Date: 
Message-ID: <1183055758.182331.26800@n2g2000hse.googlegroups.com>
thanks, strange that this was the first thing I tried and did not
work, that's why the question...
now it works.

Richard M Kreuter wrote:
> Karol Skocik <············@gmail.com> writes:
>
> >   I have a piece of code which I can reduce to something like this:
> >
> > (handler-case (some-form-causing-error)
> >           (error (condition)
> >             (... here I want to print the message from errror)
> >             nil))
> >
> > so that when in the some-form-causing-error I call (error "xxx")
> > I want to print "xxx" in the part catching the condition.
> >
> > Normally I make my own conditions but for simple prototyping I use
> > just error with string.
> >
> > Any ideas?
>
>
> (format t "~&~A~&" condition)
>
> --
> RmK
From: Carl Taylor
Subject: Re: how to print message coming from (error "...")
Date: 
Message-ID: <bJSgi.127849$Sa4.53426@bgtnsc05-news.ops.worldnet.att.net>
Karol Skocik wrote:
> Hi,
>  I have a piece of code which I can reduce to something like this:
> 
> (handler-case (some-form-causing-error)
>          (error (condition)
>            (... here I want to print the message from errror)
>            nil))
> 
> so that when in the some-form-causing-error I call (error "xxx")
> I want to print "xxx" in the part catching the condition.


Take a look at  *error-output* in the CLHS.

CL-USER 1 > 
(handler-case (/ 123 0)
     (error (condition)
         (format *error-output* "~2%~6T~S~#%" condition)
          nil))


      #<DIVISION-BY-ZERO 200BB04B>
NIL


Carl Taylor
From: Rob Warnock
Subject: Re: how to print message coming from (error "...")
Date: 
Message-ID: <jKmdnVjwF7k1fRnbnZ2dnUVZ_gCdnZ2d@speakeasy.net>
Carl Taylor <··········@att.net> wrote:
+---------------
| CL-USER 1 > 
| (handler-case (/ 123 0)
|      (error (condition)
|          (format *error-output* "~2%~6T~S~#%" condition)
|           nil))
| 
| 
|       #<DIVISION-BY-ZERO 200BB04B>
| NIL
+---------------

One usually wants "~A" here instead of "~S", since "~S" usually
just prints the unreadable object, while "~A" ("aesthetic format")
often prints much more useful information, e.g.:

    > (handler-case (/ 123 0)
        (error (condition)
          (format *error-output* "~&~A~%" condition)))

    Arithmetic error DIVISION-BY-ZERO signalled.
    Operation was KERNEL::DIVISION, operands (123 0).

    NIL
    > 

Of course, how much more depends on the implementation, but...


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607