(rontolisp) docs
← Macros

define-condition

(define-condition name (parent...) (slot...) option...)

Defines a condition type as a CLOS-subset class (see defclass) over the built-in condition hierarchy condition > serious-condition > error (> simple-error and the standard error subtypes) and warning. The parent defaults to condition; with several parents, the first provides the slot layout (single inheritance) and the rest join the type hierarchy for typep/typecase/handler-case matching only (their slots are not inherited). Slots use the defclass subset (:initarg/:initform/:reader/:accessor, plus :documentation, which is dropped). Of the class options, (:report x) — a literal string or a (lambda (condition stream) ...) — is the condition's REPORT: it is the message when the condition is signaled by error/signal/warn and the text princ, princ-to-string and format's ~A write for the condition object. prin1 / ~S are unaffected and keep the #<TYPE :SLOT value ...> instance syntax. A type that defines no :report inherits its parent's; a type that inherits none but carries the simple-condition slots (format-control/format-arguments, i.e. any subtype of simple-error/simple-warning/simple-condition) reports through format applied to them; a type with neither keeps the #<...> rendering under princ too. A print-object method on the type wins over the report, for both escape modes. (:default-initargs :initarg value ...) forwards to the generated class (defaults applied by make-condition/typed error for initargs not supplied), and (:documentation ...) is dropped. Returns the type name. On the compile path it is a top-level-only form, like defclass.

The report is what princ/~A prints; prin1/~S still shows the instance:

CL-USER> (error 'my-parse-error :input "x")
Error: input did not parse