This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Finding Text of Error

5 posts · 1549 views

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

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

I think what he is asking is
(format t "~A" er)
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

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