61 lines
9.7 KiB
HTML
61 lines
9.7 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Section 9.1</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="09_.htm">
|
|
<LINK REL=UP HREF="09_.htm">
|
|
<LINK REL=NEXT HREF="09_aa.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="09_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="09_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="09_aa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
9.1 Condition System Concepts</H2> <P>
|
|
Common Lisp constructs are described not only in terms of their behavior in situations during which they are intended to be used (see the ``Description'' part of each <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operator</I></A> specification), but in all other situations (see the ``Exceptional Situations'' part of each <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operator</I></A> specification). <P>
|
|
A situation is the evaluation of an expression in a specific context. A <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> is an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> that represents a specific situation that has been detected. <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>Conditions</I></A> are <A REL=DEFINITION HREF="26_glo_g.htm#generalized_instance"><I>generalized instances</I></A> of the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> <A REL=DEFINITION HREF="e_cnd.htm#condition"><B>condition</B></A>. A hierarchy of <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> classes is defined in Common Lisp. A <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> has <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slots</I></A> that contain data relevant to the situation that the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> represents. <P>
|
|
An error is a situation in which normal program execution cannot continue correctly without some form of intervention (either interactively by the user or under program control). Not all errors are detected. When an error goes undetected, the effects can be <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>, <A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A>, unspecified, or undefined. See <A REL=CHILD HREF="01_d.htm">Section 1.4 (Definitions)</A>. All detected errors can be represented by <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A>, but not all <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> represent errors. <P>
|
|
Signaling is the process by which a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> can alter the flow of control in a program by raising the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> which can then be <I>handled</I>. The functions <A REL=DEFINITION HREF="f_error.htm#error"><B>error</B></A>, <A REL=DEFINITION HREF="f_cerror.htm#cerror"><B>cerror</B></A>, <A REL=DEFINITION HREF="f_signal.htm#signal"><B>signal</B></A>, and <A REL=DEFINITION HREF="f_warn.htm#warn"><B>warn</B></A> are used to signal <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A>. <P>
|
|
The process of signaling involves the selection and invocation of a <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> from a set of <A REL=DEFINITION HREF="26_glo_a.htm#active"><I>active</I></A> <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handlers</I></A>. A <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> is a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> of one argument (the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>) that is invoked to handle a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>. Each <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> is associated with a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>, and a <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> will be invoked only on a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> of the <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A>'s associated <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. <P>
|
|
<A REL=DEFINITION HREF="26_glo_a.htm#active"><I>Active</I></A> <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handlers</I></A> are <I>established</I> dynamically (see <A REL=DEFINITION HREF="m_handle.htm#handler-bind"><B>handler-bind</B></A> or <A REL=DEFINITION HREF="m_hand_1.htm#handler-case"><B>handler-case</B></A>). <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>Handlers</I></A> are invoked in a <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_environment"><I>dynamic environment</I></A> equivalent to that of the signaler, except that the set of <A REL=DEFINITION HREF="26_glo_a.htm#active"><I>active</I></A> <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handlers</I></A> is bound in such a way as to include only those that were <A REL=DEFINITION HREF="26_glo_a.htm#active"><I>active</I></A> at the time the <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> being invoked was <I>established</I>. Signaling a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> has no side-effect on the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>, and there is no dynamic state contained in a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>. <P>
|
|
If a <A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>handler</I></A> is invoked, it can address the <A REL=DEFINITION HREF="26_glo_s.htm#situation"><I>situation</I></A> in one of three ways: <P>
|
|
<P><DL><DT><B>Decline</B> <P><DD>
|
|
It can decline to <A REL=DEFINITION HREF="26_glo_h.htm#handle"><I>handle</I></A> the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>. It does this by simply returning rather than transferring control. When this happens, any values returned by the handler are ignored and the next most recently established handler is invoked. If there is no such handler and the signaling function is <A REL=DEFINITION HREF="f_error.htm#error"><B>error</B></A> or <A REL=DEFINITION HREF="f_cerror.htm#cerror"><B>cerror</B></A>, the debugger is entered in the <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_environment"><I>dynamic environment</I></A> of the signaler. If there is no such handler and the signaling function is either <A REL=DEFINITION HREF="f_signal.htm#signal"><B>signal</B></A> or <A REL=DEFINITION HREF="f_warn.htm#warn"><B>warn</B></A>, the signaling function simply returns <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<DT><B>Handle</B> <P><DD>
|
|
It can <A REL=DEFINITION HREF="26_glo_h.htm#handle"><I>handle</I></A> the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> by performing a non-local transfer of control. This can be done either primitively by using <A REL=DEFINITION HREF="s_go.htm#go"><B>go</B></A>, <A REL=DEFINITION HREF="m_return.htm#return"><B>return</B></A>, <A REL=DEFINITION HREF="s_throw.htm#throw"><B>throw</B></A> or more abstractly by using a function such as <A REL=DEFINITION HREF="f_abortc.htm#abort"><B>abort</B></A> or <A REL=DEFINITION HREF="f_invo_1.htm#invoke-restart"><B>invoke-restart</B></A>. <P>
|
|
<DT><B>Defer</B> <P><DD>
|
|
It can put off a decision about whether to <A REL=DEFINITION HREF="26_glo_h.htm#handle"><I>handle</I></A> or <A REL=DEFINITION HREF="26_glo_d.htm#decline"><I>decline</I></A>, by any of a number of actions, but most commonly by signaling another condition, resignaling the same condition, or forcing entry into the debugger. <P>
|
|
<P></DL><P>
|
|
|
|
|
|
<A REL=CHILD HREF="09_aa.htm"><H2>
|
|
9.1.1 Condition Types</H2></A><P>
|
|
|
|
<A REL=CHILD HREF="09_ab.htm"><H2>
|
|
9.1.2 Creating Conditions</H2></A><P>
|
|
|
|
<A REL=CHILD HREF="09_ac.htm"><H2>
|
|
9.1.3 Printing Conditions</H2></A><P>
|
|
|
|
<A REL=CHILD HREF="09_ad.htm"><H2>
|
|
9.1.4 Signaling and Handling Conditions</H2></A><P>
|
|
|
|
<A REL=CHILD HREF="09_ae.htm"><H2>
|
|
9.1.5 Assertions</H2></A><P><P>
|
|
|
|
|
|
<A REL=CHILD HREF="09_af.htm"><H2>
|
|
9.1.6 Notes about the Condition System's Background</H2></A><P><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|