Skip to main content

control-error

control-error Condition Type

Class Precedence List:

control-error, error, serious-condition, condition, t

Description:

The type control-error consists of error conditions that result from invalid dynamic transfers of control in a program. The errors that result from giving throw a tag that is not active or from giving go or return-from a tag that is no longer dynamically available are of type control-error.

Expanded Reference: control-error

Type Hierarchy

control-error is a subtype of error that is signaled when a control transfer (such as go, return-from, or throw) attempts to use a tag or block that is no longer active.

;; control-error sits in the condition hierarchy
(subtypep 'control-error 'error)
=> T
=> T
(subtypep 'control-error 'condition)
=> T
=> T

Handling control-error with handler-case

A control-error is signaled when a throw targets a catch tag that does not exist in the dynamic scope.

;; Catching a control-error from an invalid throw
(handler-case
(throw 'nonexistent-tag 42)
(control-error (c)
(format nil "Caught control-error: ~A" c)))
;; => "Caught control-error: ..." (message is implementation-dependent)

Using typep to Identify control-error

You can test whether a condition object is of type control-error using typep.

;; Capture the condition and inspect it
(let ((condition
(handler-case
(throw 'no-such-tag nil)
(control-error (c) c))))
(values (typep condition 'control-error)
(typep condition 'error)
(typep condition 'condition)))
=> T
=> T
=> T