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