simple-type-error
simple-type-error Condition Type
Class Precedence List:
simple-type-error, simple-condition, type-error, error, serious-condition, condition, t
Description:
Conditions of type simple-type-error are like conditions of type type-error, except that they provide an alternate mechanism for specifying how the condition is to be reported; see the type simple-condition.
See Also:
simple-condition, simple-condition-format-control, simple-condition-format-arguments, type-error-datum, type-error-expected-type
Expanded Reference: simple-type-error
Signaling a simple-type-error
simple-type-error is a condition type that combines type-error and simple-condition. It supports both type-error slots (:datum, :expected-type) and a format control string.
(handler-case
(error 'simple-type-error
:datum "hello"
:expected-type 'integer
:format-control "Expected ~A but got ~S"
:format-arguments '(integer "hello"))
(simple-type-error (c)
(format nil "~A" c)))
=> "Expected INTEGER but got \"hello\""
Accessing Both Sets of Slots
(handler-case
(error 'simple-type-error
:datum 3.14
:expected-type 'integer
:format-control "~S is not an integer"
:format-arguments '(3.14))
(simple-type-error (c)
(list :datum (type-error-datum c)
:expected (type-error-expected-type c)
:message (simple-condition-format-control c))))
=> (:DATUM 3.14 :EXPECTED INTEGER :MESSAGE "~S is not an integer")