safe-format-to-string &rest format-args => string
safe-format-to-limited-string limit &rest format-args => string
safe-format-to-string
, safe-prin1-to-string
and safe-princ-to-string
are analogs to the standard functions format
(with first argument nil
), prin1-to-string
and princ-to-string
. If format-args and object can be printed without any errors then they are equivalent to the standard functions, except that they bind *print-readably*
and *print-circle*
to nil
.
The difference is when there is an error during the printing operation. The "safe" functions catch the error, and try to produce something that indicates that an error occurred during the printing operation and what it was, without causing recursive errors.
safe-format-to-limited-string
is like safe-format-to-string
, except that the length of the result string is limited to limit. The printing is stopped when the output become longer than limit and the result is a string of length limit, with the last three characters being "...". Limiting the length in this way also copes well when printing deeply nested objects.
These functions are intended to be used in code that handles and reports errors, where it is important to avoid recursive errors.
The debugging tools of the LispWorks IDE use these functions.
LispWorks User Guide and Reference Manual - 20 Sep 2017