Page 1 of 1
Finding Text of Error
Posted: Mon Mar 22, 2010 9:33 pm
by Suroy
How would i find the text that would be displayed for any error when I catch it?
So,
(handler-case (error "HI") (error (er)
;;somehow return error string ("HI") that would've been displayed if hadn't been caught
))
Re: Finding Text of Error
Posted: Mon Mar 22, 2010 11:47 pm
by ramarren
By default, that is, when the first argument to
ERROR is a string, which can be a format control string by the way, taking more arguments as arguments to format, a condition of type
SIMPLE-ERROR which is a subtype of
SIMPLE-CONDITION. You can retrieve the format control string and its arguments with
SIMPLE-CONDITION-FORMAT-CONTROL and SIMPLE-CONDITION-FORMAT-ARGUMENTS, and then pass them to
FORMAT with
APPLY to construct the final string.
But you probably should create a custom condition class if you want to introspect it.
Re: Finding Text of Error
Posted: Tue Mar 23, 2010 11:45 am
by gugamilare
I think what he is asking is
Code: Select all
cl-user> (handler-case (error "HI") (error (er)
(format t "~A~%" er)))
HI
nil
If you want a string (and not to print the text), you can use
(format nil "~A" er) instead.
Re: Finding Text of Error
Posted: Tue Mar 23, 2010 11:58 am
by ramarren
Ah, I forgot that while section
22.1.3 doesn't list conditions, their printing is specified
explicitly. PRINC or PRINC-TO-STRING would be simpler than FORMAT for that case.
Re: Finding Text of Error
Posted: Tue Mar 23, 2010 2:27 pm
by Suroy
Exactly what i needed. Thx
