condition
condition Condition Type
Class Precedence List:
condition, t
Description:
All types of conditions, whether error or non-error, must inherit from this type.
No additional subtype relationships among the specified subtypes of type condition are allowed, except when explicitly mentioned in the text; however implementations are permitted to introduce additional types and one of these types can be a subtype of any number of the subtypes of type condition.
Whether a user-defined condition type has slots that are accessible by with-slots is implementation dependent. Furthermore, even in an implementation in which user-defined condition types would have slots, it is implementation-dependent whether any condition types defined in this document have such slots or, if they do, what their names might be; only the reader functions documented by this specification may be relied upon by portable code.
Conforming code must observe the following restrictions related to conditions:
• define-condition, not defclass, must be used to define new condition types.
• make-condition, not make-instance, must be used to create condition objects explicitly.
• The :report option of define-condition, not defmethod for print-object, must be used to define a condition reporter.
• slot-value, slot-boundp, slot-makunbound, and with-slots must not be used on condition objects. Instead, the appropriate accessor functions (defined by define-condition) should be used.
Expanded Reference: condition
The Root of the Condition Hierarchy
condition is the base type for all conditions in Common Lisp. Every condition type -- whether an error, warning, or other signal -- inherits from condition.
(typep (make-condition 'simple-error :format-control "oops")
'condition)
=> T
Checking the Type Hierarchy
All standard condition types are subtypes of condition.
(subtypep 'error 'condition)
=> T
=> T
(subtypep 'warning 'condition)
=> T
=> T
(subtypep 'serious-condition 'condition)
=> T
=> T
Defining Custom Conditions
User-defined conditions must be defined with define-condition, not defclass. They must inherit from condition or one of its subtypes.
(define-condition my-notice (condition)
((message :initarg :message :reader notice-message))
(:report (lambda (c stream)
(format stream "Notice: ~A" (notice-message c)))))
(typep (make-condition 'my-notice :message "test") 'condition)
=> T
Signaling a Plain Condition
A condition that is not an error or warning can be signaled with signal. If unhandled, signal returns nil rather than entering the debugger.
(signal (make-condition 'simple-condition
:format-control "Just informing"))
=> NIL