condition
.
The condition system was influenced by the Common Lisp error system [? ]
and the Standard ML exception mechanism. It is a simplification of the former
and an extension of the latter. Following standard practice, this text defines
the actions of functions in terms of their normal behaviour. Where an
exceptional behaviour might arise, this has been defined in terms of a
condition. However, not all exceptional situations are errors. Following
Pitman, we use condition to be a kind of occasion in a program
when an exceptional situation has been signalled. An error is a kind of
condition|error and condition are also used as terms for the objects that
represent exceptional situations. A condition can be signalled continuably by
passing a continuation for the resumption to signal. If a continuation is not
supplied then the condition cannot be continued.
These two categories are characterized as follows: defcondition
(see Section ).
The definition of a condition causes the creation of a new class of condition. A
condition is signalled using the function signal
, which has
two required arguments and one optional argument: an instance of a
condition, a resume continuation or the empty list, the latter signifying a
non-continuable signal, and a thread. A condition can be handled using the
special form with-handler
, which takes a function, the
handler function, and a sequence of forms to be protected. The initial
condition class hierarchy is as follows:
call-next-handler | conditionp | <condition> |
---|---|---|
defcondition | initialize | signal |
with-handler | <wrong-condition-class> |
defcondition : defining
form | INDEX |
()
, the superclass is taken to
be <condition>
. Otherwise
superclass-name must be <condition>
or
the name of one of its subclasses.
:
class | INDEX |
<string>
<list>
conditionp :
function | INDEX |
()
.
initialize : method | INDEX |
(condition <condition>
)
<string>
<list>
call-next-method
to carry out
initialization specified by superclasses then does the condition
specific initialization.
:
<thread-condition> | INDEX |
condition
signal
if the given condition is not an instance
of the condition class <thread-condition>
.
with-handler
.
signal : function | INDEX |
signal
,
otherwise, thread indicates the thread on which
condition is to be signalled.
signal
calls the nearest
enclosing handler with condition.
If the second argument is supplied, signal
registers the
specified condition to be signalled on thread. The condition must
be an instance of the condition class
<thread-condition>
, otherwise an error is signalled
(condition class: <wrong-condition-class>
) on the
thread calling signal
. A signal
on a
determined thread has no effect on either the signalled or signalling thread
except in the case of the above error.
thread-reschedule
,
thread-value
, with-handler
.
call-next-handler : special
form | INDEX |
call-next-handler
special form calls
the next enclosing handler. It is an error to evaluate this form other than
within an established handler function.
The call-next-handler
special form is normally used when a
handler function does not know how to deal with the class of condition.
However, it may also be used to combine handler function behaviour in a
similar but orthogonal way to call-next-method
(assuming a
generic handler function).
with-handler : special
form | INDEX |
signal
as its first argument. The
resume continuation is the continuation (or
()
) that was given to signal
as its
second argument.
with-handler
form is evaluated in three
steps: with-handler
expression.
with-handler
. The
exceptional behaviour of with-handler
happens when there is
a call to signal
during the evaluation of
protected-form. signal
calls the nearest enclosing
handler-function passing on the first two arguments given to
signal
. The handler-function is executed in the
dynamic extent of the call to signal
. However, any calls to
signal
s occurring during the execution of
handler-function are dealt with by the nearest enclosing handler
outside the extent of the form which established handler-function.
It is an error if there is no enclosing handler. In this circumstance the
identified error is delivered to the configuration to be dealt with in an
implementation-defined way. Errors arising in the dynamic extent of the
handler function are signalled in the dynamic extent of the original
signal
but are handled in the enclosing dynamic extent of
the handler.
signal
returns with the result
passed back from the handler function.
call-next-handler
special
form.
signal
.