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
))
Finding Text of Error
Re: Finding Text of Error
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.
But you probably should create a custom condition class if you want to introspect it.
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: Finding Text of Error
I think what he is asking is
If you want a string (and not to print the text), you can use (format nil "~A" er) instead.
Code: Select all
(format t "~A" er)
Code: Select all
cl-user> (handler-case (error "HI") (error (er)
(format t "~A~%" er)))
HI
nil
Re: Finding Text of Error
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
Exactly what i needed. Thx 
