我目前正在使用 cxml-stp 框架进行开发,但在解析时,我确实得到了一个 cxml-stp:stp-error,这是一个简单错误的子类,它被记录为一种提供格式控件的错误。
如何打印错误消息?由于 API 都没有提供任何特定函数,并且简单的FORMAT
只会导致打印对象,但不使用提供的 FORMAT 字符串。
例如
(SB-KERNEL:CASE-FAILURE
ETYPECASE
#<CXML-STP:STP-ERROR "text includes characters that cannot be ~
represented in XML at all: ~S"
{1007814951}>
(STRING SIMPLE-STRING))
只需编写条件对象而不进行转义:
(write condition :escape nil)
(defun try-handle-error (err)
(handler-case
(error err)
(serious-condition (condition)
(apply #'format
(nconc (list t)
(cons (simple-condition-format-control condition)
(simple-condition-format-arguments condition)))))))
(try-handle-error (make-condition
'simple-error
:format-control "say something ~s~&"
:format-arguments '(42)))
这将是一个例子。基本上,格式控制和格式参数是在简单错误类上声明的时隙读取器。处理错误时,可以针对该错误调用它们,以获取它在创建过程中收到的值。