Skip to main content

unbound-slot-instance

unbound-slot-instance Function

Syntax:

unbound-slot-instance condition ! instance

Arguments and Values:

condition—a condition of type unbound-slot.

instance—an object.

Description:

Returns the instance which had the unbound slot in the situation represented by the condition.

See Also:

cell-error-name, unbound-slot, Section 9.1 (Condition System Concepts)

Expanded Reference: unbound-slot-instance

Accessing the Instance from an unbound-slot Condition

unbound-slot-instance returns the object that had the unbound slot when the unbound-slot condition was signaled.

(defclass item ()
((name :initarg :name)
(price :initarg :price)))

(let ((obj (make-instance 'item :name "Widget")))
(handler-case (slot-value obj 'price)
(unbound-slot (c)
(let ((inst (unbound-slot-instance c)))
(format nil "Slot ~A unbound in ~A (a ~A)"
(cell-error-name c)
(slot-value inst 'name)
(class-name (class-of inst)))))))
=> "Slot PRICE unbound in Widget (a ITEM)"

Combining with cell-error-name

Together, unbound-slot-instance and cell-error-name provide complete information about the unbound slot access.

(defclass config ()
((host :initarg :host)
(port :initarg :port)))

(let ((c (make-instance 'config :host "localhost")))
(handler-case (slot-value c 'port)
(unbound-slot (condition)
(list :slot-name (cell-error-name condition)
:same-instance-p (eq c (unbound-slot-instance condition))))))
=> (:SLOT-NAME PORT :SAME-INSTANCE-P T)