1
0
Fork 0
cl-sites/lisp-docs.github.io/cl-language-reference/chap-9/j-b-condition-system-concepts.html

202 lines
67 KiB
HTML
Raw Normal View History

2024-03-13 23:00:32 +01:00
<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-chap-9/j-b-condition-system-concepts" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.0.1">
<title data-rh="true">9.1 Condition System Concepts | Common Lisp (New) Language Reference</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" name="twitter:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" property="og:url" content="https://lisp-docs.github.io/cl-language-reference/chap-9/j-b-condition-system-concepts"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="google-site-verification" content="Vzaw013_bfdKeUVG89Ch3W1zC9_vH9ID2dPB9Dz0vr0"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="9.1 Condition System Concepts | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="9.1.1 Condition Types"><meta data-rh="true" property="og:description" content="9.1.1 Condition Types"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="j-b-condition-system-concepts.html"><link data-rh="true" rel="alternate" href="j-b-condition-system-concepts.html" hreflang="en"><link data-rh="true" rel="alternate" href="j-b-condition-system-concepts.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://C1F2Q5VM6X-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://www.googletagmanager.com">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8TJCE4NSF8"></script>
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-8TJCE4NSF8",{})</script>
<link rel="search" type="application/opensearchdescription+xml" title="Common Lisp (New) Language Reference" href="../opensearch.xml"><link rel="stylesheet" href="../assets/css/styles.f13b59fe.css">
<script src="../assets/js/runtime~main.02699c25.js" defer="defer"></script>
<script src="../assets/js/main.4f0a7a76.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="j-b-condition-system-concepts.html#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="../../index.html" target="_blank" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Common Lisp Docs</b></a><a href="../../docs/tutorial/index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Tutorial</a><a href="../index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Technical Reference</a><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Why Lisp?</a><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Guides</a></div><div class="navbar__items navbar__items--right"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Contribute!</a><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Getting Help</a><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">About</a><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Blog</a><a href="https://github.com/lisp-docs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M
<!-- -->
<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 <span><i>operator</i></span> specification), but in all other situations (see the “Exceptional Situations” part of each <span><i>operator</i></span> specification).</p>
<p>A situation is the evaluation of an expression in a specific context. A <span><i>condition</i></span> is an <span><i>object</i></span> that represents a specific situation that has been detected. <span><i>Conditions</i></span> are <span><i>generalized instances</i></span> of the <span><i>class</i></span> <span><b>condition</b></span>. A hierarchy of <span><i>condition</i></span> classes is defined in Common Lisp. A <span><i>condition</i></span> has <span><i>slots</i></span> that contain data relevant to the situation that the <span><i>condition</i></span> represents.</p>
<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 <span><i>implementation-dependent</i></span>, <span><i>implementation-defined</i></span>, unspecified, or undefined. See Section 1.4 (Definitions). All detected errors can be represented by <span><i>conditions</i></span>, but not all <span><i>conditions</i></span> represent errors.</p>
<p>Signaling is the process by which a <span><i>condition</i></span> can alter the flow of control in a program by raising the <span><i>condition</i></span> which can then be <em>handled</em>. The functions <span><b>error</b></span>, <span><b>cerror</b></span>, <span><b>signal</b></span>, and <span><b>warn</b></span> are used to signal <span><i>conditions</i></span>.</p>
<p>The process of signaling involves the selection and invocation of a <span><i>handler</i></span> from a set of <em>active handlers</em>. A <span><i>handler</i></span> is a <span><i>function</i></span> of one argument (the <span><i>condition</i></span>) that is invoked to handle a <span><i>condition</i></span>. Each <span><i>handler</i></span> is associated with a <em>condition type</em>, and a <span><i>handler</i></span> will be invoked only on a <span><i>condition</i></span> of the <span><i>handler</i></span> s associated <span><i>type</i></span>.</p>
<p><em>Active handlers</em> are <em>established</em> dynamically (see <span><b>handler-bind</b></span> or <span><b>handler-case</b></span>). <span><i>Handlers</i></span> are invoked in a <span><i>dynamic environment</i></span> equivalent to that of the signaler, except that the set of <em>active handlers</em> is bound in such a way as to include only those that were <span><i>active</i></span> at the time the <span><i>handler</i></span> being invoked was <em>established</em>. Signaling a <span><i>condition</i></span> has no side-effect on the <span><i>condition</i></span>, and there is no dynamic state contained in a <span><i>condition</i></span>.</p>
<p>If a <span><i>handler</i></span> is invoked, it can address the <span><i>situation</i></span> in one of three ways:</p>
<p><strong>Decline</strong></p>
<p>It can decline to <span><i>handle</i></span> the <span><i>condition</i></span>. 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 <span><b>error</b></span> or <span><b>cerror</b></span>, the debugger is entered in the <span><i>dynamic environment</i></span> of the signaler. If there is no such handler and the signaling function is either <span><b>signal</b></span> or <span><b>warn</b></span>, the signaling function simply returns <span><b>nil</b></span>.</p>
<p><strong>Handle</strong></p>
<p>It can <span><i>handle</i></span> the <span><i>condition</i></span> by performing a non-local transfer of control. This can be done either primitively by using <span><b>go</b></span>, <span><b>return</b></span>, <span><b>throw</b></span> or more abstractly by using a function such as <strong>abort</strong> or <span><b>invoke-restart</b></span>.</p>
<p><strong>Defer</strong></p>
<p>It can put off a decision about whether to <span><i>handle</i></span> or <span><i>decline</i></span>, 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>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="911-condition-types">9.1.1 Condition Types<a href="j-b-condition-system-concepts.html#911-condition-types" class="hash-link" aria-label="Direct link to 9.1.1 Condition Types" title="Direct link to 9.1.1 Condition Types"></a></h2>
<!-- -->
<p>Figure 91 lists the <em>standardized condition types</em>. Additional <em>condition types</em> can be defined by using <span><b>define-condition</b></span>.</p>
<p>|<strong>arithmetic-error floating-point-overflow simple-type-error cell-error floating-point-underflow simple-warning condition package-error storage-condition control-error parse-error stream-error division-by-zero print-not-readable style-warning end-of-file program-error type-error error reader-error unbound-slot file-error serious-condition unbound-variable floating-point-inexact simple-condition undefined-function floating-point-invalid-operation simple-error warning</strong>|</p>
<p>| :- |</p>
<p><strong>Figure 91. Standardized Condition Types</strong></p>
<p>All <span><i>condition</i></span> types are <span><i>subtypes</i></span> of <span><i>type</i></span> <span><b>condition</b></span>. That is,</p>
<p>(typep <em>c</em> condition) → true</p>
<p>if and only if <em>c</em> is a <span><i>condition</i></span>.</p>
<p><span><i>Implementations</i></span> must define all specified <span><i>subtype</i></span> relationships. Except where noted, all <span><i>subtype</i></span> relationships indicated in this document are not mutually exclusive. A <span><i>condition</i></span> inherits the structure of its <span><i>supertypes</i></span>.</p>
<p>The metaclass of the <span><i>class</i></span> <span><b>condition</b></span> is not specified. <span><i>Names</i></span> of <em>condition types</em> may be used to specify <span><i>supertype</i></span> relationships in <span><b>define-condition</b></span>, but the consequences are not specified if an attempt is made to use a <em>condition type</em> as a <span><i>superclass</i></span> in a <span><b>defclass</b></span> <span><i>form</i></span>.</p>
<p>Figure 92 shows <span><i>operators</i></span> that define <em>condition types</em> and creating <span><i>conditions</i></span>.</p>
<p>|<strong>define-condition make-condition</strong>|</p>
<p>| :- |</p>
<p><strong>Figure 92. Operators that define and create conditions.</strong></p>
<p>Figure 93 shows <span><i>operators</i></span> that <span><i>read</i></span> the <span><i>value</i></span> of <em>condition slots</em>.</p>
<p>|</p><p><strong>arithmetic-error-operands simple-condition-format-arguments arithmetic-error-operation simple-condition-format-control cell-error-name stream-error-stream</strong> </p><p><strong>file-error-pathname type-error-datum</strong> </p><p><strong>package-error-package type-error-expected-type</strong> </p><p><strong>print-not-readable-object unbound-slot-instance</strong></p>|<p></p>
<p>| :- |</p>
<p><strong>Figure 93. Operators that read condition slots.</strong></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="9111-serious-conditions">9.1.1.1 Serious Conditions<a href="j-b-condition-system-concepts.html#9111-serious-conditions" class="hash-link" aria-label="Direct link to 9.1.1.1 Serious Conditions" title="Direct link to 9.1.1.1 Serious Conditions"></a></h3>
<!-- -->
<p>A <span><i>serious condition</i></span> is a <span><i>condition</i></span> serious enough to require interactive intervention if not handled. <span><i>Serious conditions</i></span> are typically signaled with <span><b>error</b></span> or <span><b>cerror</b></span>; non-serious <span><i>conditions</i></span> are typically signaled with <span><b>signal</b></span> or <span><b>warn</b></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="912-creating-conditions">9.1.2 Creating Conditions<a href="j-b-condition-system-concepts.html#912-creating-conditions" class="hash-link" aria-label="Direct link to 9.1.2 Creating Conditions" title="Direct link to 9.1.2 Creating Conditions"></a></h2>
<!-- -->
<p>The function <span><b>make-condition</b></span> can be used to construct a <em>condition object</em> explicitly. Functions such as <span><b>error</b></span>, <span><b>cerror</b></span>, <span><b>signal</b></span>, and <span><b>warn</b></span> operate on <span><i>conditions</i></span> and might create <em>condition objects</em> implicitly. Macros such as <span><b>ccase</b></span>, <span><b>ctypecase</b></span>, <span><b>ecase</b></span>, <span><b>etypecase</b></span>, <span><b>check-type</b></span>, and <span><b>assert</b></span> might also implicitly create (and <span><i>signal</i></span>) <span><i>conditions</i></span>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="9121-condition-designators">9.1.2.1 Condition Designators<a href="j-b-condition-system-concepts.html#9121-condition-designators" class="hash-link" aria-label="Direct link to 9.1.2.1 Condition Designators" title="Direct link to 9.1.2.1 Condition Designators"></a></h3>
<!-- -->
<p>A number of the functions in the condition system take arguments which are identified as <span><i>condition designators</i></span>. By convention, those arguments are notated as</p>
<p><em>datum</em> &amp;rest <span><i>arguments</i></span></p>
<p>Taken together, the <em>datum</em> and the <span><i>arguments</i></span> are “<span><i>designators</i></span> for a <span><i>condition</i></span> of default type <em>default-type</em>.” How the denoted <span><i>condition</i></span> is computed depends on the type of the <em>datum</em>:</p>
<p><em></em> If the <em>datum</em> is a <span><i>symbol</i></span> naming a <em>condition type . . .</em></p>
<p>The denoted <span><i>condition</i></span> is the result of</p>
<p>(apply #make-condition <em>datum arguments</em>)</p>
<p><em></em> If the <em>datum</em> is a <em>format control . . .</em></p>
<p>The denoted <span><i>condition</i></span> is the result of</p>
<p>(make-condition <em>defaulted-type</em></p>
<p>:format-control<!-- --> <em>datum</em></p>
<p>:format-arguments<!-- --> <span><i>arguments</i></span>)</p>
<p>where the <em>defaulted-type</em> is a <span><i>subtype</i></span> of <em>default-type</em>.</p>
<p><em></em> If the <em>datum</em> is a <em>condition . . .</em></p>
<p>The denoted <span><i>condition</i></span> is the <em>datum</em> itself. In this case, unless otherwise specified by the description of the <span><i>operator</i></span> in question, the <span><i>arguments</i></span> must be <span><i>null</i></span>; that is, the consequences are undefined if any <span><i>arguments</i></span> were supplied.</p>
<p>Note that the <em>default-type</em> gets used only in the case where the <em>datum string</em> is supplied. In the other situations, the resulting condition is not necessarily of <em>type default-type</em>.</p>
<p>Here are some illustrations of how different <span><i>condition designators</i></span> can denote equivalent <em>condition objects</em>:</p>
<p>(let ((c (make-condition arithmetic-error <!-- -->:operator<!-- --> / <!-- -->:operands<!-- --> (7 0))))</p>
<p>(error c))</p>
<p><em></em> (error arithmetic-error <!-- -->:operator<!-- --> / <!-- -->:operands<!-- --> (7 0))</p>
<p>(error &quot;Bad luck.&quot;)</p>
<p><em></em> (error simple-error <!-- -->:format-control<!-- --> &quot;Bad luck.&quot; <!-- -->:format-arguments<!-- --> ())</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="913-printing-conditions">9.1.3 Printing Conditions<a href="j-b-condition-system-concepts.html#913-printing-conditions" class="hash-link" aria-label="Direct link to 9.1.3 Printing Conditions" title="Direct link to 9.1.3 Printing Conditions"></a></h2>
<!-- -->
<p>If the <!-- -->:report<!-- --> argument to <span><b>define-condition</b></span> is used, a print function is defined that is called whenever the defined <span><i>condition</i></span> is printed while the <span><i>value</i></span> of <span><b>*print-escape*</b></span> is <span><i>false</i></span>. This function is called the <span><i>condition reporter</i></span>; the text which it outputs is called a <span><i>report message</i></span>.</p>
<p>When a <span><i>condition</i></span> is printed and <span><b>*print-escape*</b></span> is <span><i>false</i></span>, the <span><i>condition reporter</i></span> for the <span><i>condition</i></span> is invoked. <span><i>Conditions</i></span> are printed automatically by functions such as <span><b>invoke-debugger</b></span>, <span><b>break</b></span>, and <span><b>warn</b></span>.</p>
<p>When <span><b>*print-escape*</b></span> is <span><i>true</i></span>, the <span><i>object</i></span> should print in an abbreviated fashion according to the style of the implementation (<em>e.g.</em>, by <span><b>print-unreadable-object</b></span>). It is not required that a <span><i>condition</i></span> can be recreated by reading its printed representation.</p>
<p>No <span><i>function</i></span> is provided for directly <em>accessing</em> or invoking <span><i>condition reporters</i></span>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="9131-recommended-style-in-condition-reporting">9.1.3.1 Recommended Style in Condition Reporting<a href="j-b-condition-system-concepts.html#9131-recommended-style-in-condition-reporting" class="hash-link" aria-label="Direct link to 9.1.3.1 Recommended Style in Condition Reporting" title="Direct link to 9.1.3.1 Recommended Style in Condition Reporting"></a></h3>
<!-- -->
<p>In order to ensure a properly aesthetic result when presenting <span><i>report messages</i></span> to the user, certain stylistic conventions are recommended.</p>
<p>There are stylistic recommendations for the content of the messages output by <span><i>condition reporters</i></span>, but there are no formal requirements on those <span><i>programs</i></span>. If a <span><i>program</i></span> violates the recommendations for some message, the display of that message might be less aesthetic than if the guideline had been observed, but the <span><i>program</i></span> is still considered a <span><i>conforming program</i></span>.</p>
<p>The requirements on a <span><i>program</i></span> or <span><i>implementation</i></span> which invokes a <span><i>condition reporter</i></span> are somewhat stronger. A <span><i>conforming program</i></span> must be permitted to assume that if these style guidelines are followed, proper aesthetics will be maintained. Where appropriate, any specific requirements on such routines are explicitly mentioned below.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91311-capitalization-and-punctuation-in-condition-reports">9.1.3.1.1 Capitalization and Punctuation in Condition Reports<a href="j-b-condition-system-concepts.html#91311-capitalization-and-punctuation-in-condition-reports" class="hash-link" aria-label="Direct link to 9.1.3.1.1 Capitalization and Punctuation in Condition Reports" title="Direct link to 9.1.3.1.1 Capitalization and Punctuation in Condition Reports"></a></h4>
<!-- -->
<p>It is recommended that a <span><i>report message</i></span> be a complete sentences, in the proper case and correctly punctuated. In English, for example, this means the first letter should be uppercase, and there should be a trailing period.</p>
<p>(error &quot;This is a message&quot;) ; Not recommended</p>
<p>(error &quot;this is a message.&quot;) ; Not recommended</p>
<p>(error &quot;This is a message.&quot;) ; Recommended instead</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91312-leading-and-trailing-newlines-in-condition-reports">9.1.3.1.2 Leading and Trailing Newlines in Condition Reports<a href="j-b-condition-system-concepts.html#91312-leading-and-trailing-newlines-in-condition-reports" class="hash-link" aria-label="Direct link to 9.1.3.1.2 Leading and Trailing Newlines in Condition Reports" title="Direct link to 9.1.3.1.2 Leading and Trailing Newlines in Condition Reports"></a></h4>
<!-- -->
<p>It is recommended that a <span><i>report message</i></span> not begin with any introductory text, such as “Error: ” or “Warning: ” or even just <span><i>freshline</i></span> or <span><i>newline</i></span>. Such text is added, if appropriate to the context, by the routine invoking the <span><i>condition reporter</i></span> .</p>
<p>It is recommended that a <span><i>report message</i></span> not be followed by a trailing <span><i>freshline</i></span> or <span><i>newline</i></span>. Such text is added, if appropriate to the context, by the routine invoking the <span><i>condition reporter</i></span> .</p>
<p>(error &quot;This is a message.~%&quot;) ; Not recommended</p>
<p>(error &quot;~&amp;This is a message.&quot;) ; Not recommended</p>
<p>(error &quot;~&amp;This is a message.~%&quot;) ; Not recommended</p>
<p>(error &quot;This is a message.&quot;) ; Recommended instead</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91313-embedded-newlines-in-condition-reports">9.1.3.1.3 Embedded Newlines in Condition Reports<a href="j-b-condition-system-concepts.html#91313-embedded-newlines-in-condition-reports" class="hash-link" aria-label="Direct link to 9.1.3.1.3 Embedded Newlines in Condition Reports" title="Direct link to 9.1.3.1.3 Embedded Newlines in Condition Reports"></a></h4>
<!-- -->
<p>Especially if it is long, it is permissible and appropriate for a <span><i>report message</i></span> to contain one or more embedded <span><i>newlines</i></span>.</p>
<p>If the calling routine conventionally inserts some additional prefix (such as “Error: ” or “;; Error: ”) on the first line of the message, it must also assure that an appropriate prefix will</p>
<p>be added to each subsequent line of the output, so that the left edge of the message output by the <span><i>condition reporter</i></span> will still be properly aligned.</p>
<p>(defun test ()</p>
<p>(error &quot;This is an error message.~%It has two lines.&quot;))</p>
<p>;; Implementation A</p>
<p>(test)</p>
<p>This is an error message.</p>
<p>It has two lines.</p>
<p>;; Implementation B</p>
<p>(test)</p>
<p>;; Error: This is an error message.</p>
<p>;; It has two lines.</p>
<p>;; Implementation C</p>
<p>(test)</p>
<p>» Error: This is an error message.</p>
<p>It has two lines.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91314-note-about-tabs-in-condition-reports">9.1.3.1.4 Note about Tabs in Condition Reports<a href="j-b-condition-system-concepts.html#91314-note-about-tabs-in-condition-reports" class="hash-link" aria-label="Direct link to 9.1.3.1.4 Note about Tabs in Condition Reports" title="Direct link to 9.1.3.1.4 Note about Tabs in Condition Reports"></a></h4>
<!-- -->
<p>Because the indentation of a <span><i>report message</i></span> might be shifted to the right or left by an arbitrary amount, special care should be taken with the semi-standard <em>character ⟨Tab⟩</em> (in those <span><i>implementations</i></span> that support such a <span><i>character</i></span> ). Unless the <span><i>implementation</i></span> specifically defines its behavior in this context, its use should be avoided.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91315-mentioning-containing-function-in-condition-reports">9.1.3.1.5 Mentioning Containing Function in Condition Reports<a href="j-b-condition-system-concepts.html#91315-mentioning-containing-function-in-condition-reports" class="hash-link" aria-label="Direct link to 9.1.3.1.5 Mentioning Containing Function in Condition Reports" title="Direct link to 9.1.3.1.5 Mentioning Containing Function in Condition Reports"></a></h4>
<!-- -->
<p>The name of the containing function should generally not be mentioned in <span><i>report messages</i></span>. It is assumed that the <span><i>debugger</i></span> will make this information accessible in situations where it is necessary and appropriate.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="914-signaling-and-handling-conditions">9.1.4 Signaling and Handling Conditions<a href="j-b-condition-system-concepts.html#914-signaling-and-handling-conditions" class="hash-link" aria-label="Direct link to 9.1.4 Signaling and Handling Conditions" title="Direct link to 9.1.4 Signaling and Handling Conditions"></a></h2>
<!-- -->
<p>The operation of the condition system depends on the ordering of active <span><i>applicable handlers</i></span> from most recent to least recent.</p>
<p>Each <span><i>handler</i></span> is associated with a <span><i>type specifier</i></span> that must designate a <span><i>subtype</i></span> of <span><i>type</i></span> <span><b>condition</b></span>. A <span><i>handler</i></span> is said to be <span><i>applicable</i></span> to a <span><i>condition</i></span> if that <span><i>condition</i></span> is of the <span><i>type</i></span> designated by the associated <span><i>type specifier</i></span> .</p>
<p><em>Active handlers</em> are <em>established</em> by using <span><b>handler-bind</b></span> (or an abstraction based on <span><b>handler-bind</b></span>, such as <span><b>handler-case</b></span> or <span><b>ignore-errors</b></span>).</p>
<p><em>Active handlers</em> can be <em>established</em> within the dynamic scope of other <em>active handlers</em>. At any point during program execution, there is a set of <em>active handlers</em>. When a <span><i>condition</i></span> is signaled, the <em>most</em></p>
<p><em>recent</em> active <span><i>applicable handler</i></span> for that <span><i>condition</i></span> is selected from this set. Given a <span><i>condition</i></span>, the order of recentness of active <span><i>applicable handlers</i></span> is defined by the following two rules:</p>
<p>1. Each handler in a set of active handlers <em>H</em><sub>1</sub> is more recent than every handler in a set <em>H</em><sub>2</sub> if the handlers in <em>H</em><sub>2</sub> were active when the handlers in <em>H</em><sub>1</sub> were established.</p>
<p>2. Let <em>h</em><sub>1</sub> and <em>h</em><sub>2</sub> be two applicable active handlers established by the same <span><i>form</i></span>. Then <em>h</em><sub>1</sub> is more recent than <em>h</em><sub>2</sub> if <em>h</em><sub>1</sub> was defined to the left of <em>h</em><sub>2</sub> in the <span><i>form</i></span> that established them.</p>
<p>Once a handler in a handler binding <span><i>form</i></span> (such as <span><b>handler-bind</b></span> or <span><b>handler-case</b></span>) has been selected, all handlers in that <span><i>form</i></span> become inactive for the remainder of the signaling process. While the selected <span><i>handler</i></span> runs, no other <span><i>handler</i></span> established by that <span><i>form</i></span> is active. That is, if the <span><i>handler</i></span> declines, no other handler established by that <span><i>form</i></span> will be considered for possible invocation.</p>
<p>Figure 94 shows <span><i>operators</i></span> relating to the <em>handling</em> of <span><i>conditions</i></span>.</p>
<p>|<strong>handler-bind handler-case ignore-errors</strong>|</p>
<p>| :- |</p>
<p><strong>Figure 94. Operators relating to handling conditions.</strong></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="9141-signaling">9.1.4.1 Signaling<a href="j-b-condition-system-concepts.html#9141-signaling" class="hash-link" aria-label="Direct link to 9.1.4.1 Signaling" title="Direct link to 9.1.4.1 Signaling"></a></h3>
<!-- -->
<p>When a <span><i>condition</i></span> is signaled, the most recent applicable <em>active handler</em> is invoked. Sometimes a handler will decline by simply returning without a transfer of control. In such cases, the next most recent applicable active handler is invoked.</p>
<p>If there are no applicable handlers for a <span><i>condition</i></span> that has been signaled, or if all applicable handlers decline, the <span><i>condition</i></span> is unhandled.</p>
<p>The functions <span><b>cerror</b></span> and <span><b>error</b></span> invoke the interactive <span><i>condition</i></span> handler (the debugger) rather than return if the <span><i>condition</i></span> being signaled, regardless of its <span><i>type</i></span>, is unhandled. In contrast, <span><b>signal</b></span> returns <span><b>nil</b></span> if the <span><i>condition</i></span> being signaled, regardless of its <span><i>type</i></span>, is unhandled.</p>
<p>The <span><i>variable</i></span> <span><b>*break-on-signals*</b></span> can be used to cause the debugger to be entered before the signaling process begins.</p>
<p>Figure 95 shows <span><i>defined names</i></span> relating to the <em>signaling</em> of <span><i>conditions</i></span>.</p>
<p>|</p><p><strong>*break-on-signals* error warn</strong> </p><p><strong>cerror signal</strong></p>|<p></p>
<p>| :- |</p>
<p><strong>Figure 95. Defined names relating to signaling conditions.</strong></p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91411-resignaling-a-condition">9.1.4.1.1 Resignaling a Condition<a href="j-b-condition-system-concepts.html#91411-resignaling-a-condition" class="hash-link" aria-label="Direct link to 9.1.4.1.1 Resignaling a Condition" title="Direct link to 9.1.4.1.1 Resignaling a Condition"></a></h4>
<!-- -->
<p>During the <span><i>dynamic extent</i></span> of the <em>signaling</em> process for a particular <em>condition object<span><i>, </i></span><em>signaling</em></em> the same <em>condition object</em> again is permitted if and only if the <span><i>situation</i></span> represented in both cases are the same.</p>
<p>For example, a <span><i>handler</i></span> might legitimately <span><i>signal</i></span> the <em>condition object</em> that is its <span><i>argument</i></span> in order to allow outer <span><i>handlers</i></span> first opportunity to <span><i>handle</i></span> the condition. (Such a <span><i>handlers</i></span> is sometimes called a “default handler.”) This action is permitted because the <span><i>situation</i></span> which the second <em>signaling</em> process is addressing is really the same <span><i>situation</i></span>.</p>
<p>On the other hand, in an <span><i>implementation</i></span> that implemented asynchronous keyboard events by interrupting the user process with a call to <span><b>signal</b></span>, it would not be permissible for two distinct asynchronous keyboard events to <em>signal identical condition objects</em> at the same time for different situations.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="9142-restarts">9.1.4.2 Restarts<a href="j-b-condition-system-concepts.html#9142-restarts" class="hash-link" aria-label="Direct link to 9.1.4.2 Restarts" title="Direct link to 9.1.4.2 Restarts"></a></h3>
<!-- -->
<p>The interactive condition handler returns only through non-local transfer of control to specially defined <span><i>restarts</i></span> that can be set up either by the system or by user code. Transferring control to a restart is called “invoking” the restart. Like handlers, active <span><i>restarts</i></span> are <em>established</em> dynamically, and only active <span><i>restarts</i></span> can be invoked. An active <span><i>restart</i></span> can be invoked by the user from the debugger or by a program by using <span><b>invoke-restart</b></span>.</p>
<p>A <span><i>restart</i></span> contains a <span><i>function</i></span> to be <em>called</em> when the <span><i>restart</i></span> is invoked, an optional name that can be used to find or invoke the <span><i>restart</i></span>, and an optional set of interaction information for the debugger to use to enable the user to manually invoke a <span><i>restart</i></span>.</p>
<p>The name of a <span><i>restart</i></span> is used by <span><b>invoke-restart</b></span>. <span><i>Restarts</i></span> that can be invoked only within the debugger do not need names.</p>
<p><span><i>Restarts</i></span> can be established by using <span><b>restart-bind</b></span>, <span><b>restart-case</b></span>, and <span><b>with-simple-restart</b></span>. A <span><i>restart</i></span> function can itself invoke any other <span><i>restart</i></span> that was active at the time of establishment of the <span><i>restart</i></span> of which the <span><i>function</i></span> is part.</p>
<p>The <em>restarts established</em> by a <span><b>restart-bind</b></span> <span><i>form</i></span>, a <span><b>restart-case</b></span> <span><i>form</i></span>, or a <span><b>with-simple-restart</b></span> <span><i>form</i></span> have <span><i>dynamic extent</i></span> which extends for the duration of that <span><i>form</i></span>s execution.</p>
<p><span><i>Restarts</i></span> of the same name can be ordered from least recent to most recent according to the following two rules:</p>
<p>1. Each <span><i>restart</i></span> in a set of active restarts <em>R</em><sub>1</sub> is more recent than every <span><i>restart</i></span> in a set <em>R</em><sub>2</sub> if the <span><i>restarts</i></span> in <em>R</em><sub>2</sub> were active when the <span><i>restarts</i></span> in <em>R</em><sub>1</sub> were established.</p>
<p>2. Let <em>r</em><sub>1</sub> and <em>r</em><sub>2</sub> be two active <span><i>restarts</i></span> with the same name established by the same <span><i>form</i></span>. Then <em>r</em><sub>1</sub> is more recent than <em>r</em><sub>2</sub> if <em>r</em><sub>1</sub> was defined to the left of <em>r</em><sub>2</sub> in the <span><i>form</i></span> that established them.</p>
<p>If a <span><i>restart</i></span> is invoked but does not transfer control, the values resulting from the <span><i>restart</i></span> function are returned by the function that invoked the restart, either <span><b>invoke-restart</b></span> or <span><b>invoke-restart-interactively</b></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91421-interactive-use-of-restarts">9.1.4.2.1 Interactive Use of Restarts<a href="j-b-condition-system-concepts.html#91421-interactive-use-of-restarts" class="hash-link" aria-label="Direct link to 9.1.4.2.1 Interactive Use of Restarts" title="Direct link to 9.1.4.2.1 Interactive Use of Restarts"></a></h4>
<!-- -->
<p>For interactive handling, two pieces of information are needed from a <span><i>restart</i></span>: a report function and an interactive function.</p>
<p>The report function is used by a program such as the debugger to present a description of the action the <span><i>restart</i></span> will take. The report function is specified and established by the <!-- -->:report-function<!-- --> keyword to <span><b>restart-bind</b></span> or the <!-- -->:report<!-- --> keyword to <span><b>restart-case</b></span>.</p>
<p>The interactive function, which can be specified using the <!-- -->:interactive-function<!-- --> keyword to <span><b>restart-bind</b></span> or <!-- -->:interactive<!-- --> keyword to <span><b>restart-case</b></span>, is used when the <span><i>restart</i></span> is invoked interactively, such as from the debugger, to produce a suitable list of arguments.</p>
<p><span><b>invoke-restart</b></span> invokes the most recently <em>established restart</em> whose name is the same as the first argument to <span><b>invoke-restart</b></span>. If a <span><i>restart</i></span> is invoked interactively by the debugger and does not transfer control but rather returns values, the precise action of the debugger on those values is <span><i>implementation-defined</i></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91422-interfaces-to-restarts">9.1.4.2.2 Interfaces to Restarts<a href="j-b-condition-system-concepts.html#91422-interfaces-to-restarts" class="hash-link" aria-label="Direct link to 9.1.4.2.2 Interfaces to Restarts" title="Direct link to 9.1.4.2.2 Interfaces to Restarts"></a></h4>
<!-- -->
<p>Some <span><i>restarts</i></span> have functional interfaces, such as <strong>abort</strong>, <strong>continue</strong>, <strong>muffle-warning</strong>, <strong>store-value</strong>, and <strong>use-value</strong>. They are ordinary functions that use <span><b>find-restart</b></span> and <span><b>invoke-restart</b></span> internally, that have the same name as the <span><i>restarts</i></span> they manipulate, and that are provided simply for notational convenience.</p>
<p>Figure 96 shows <span><i>defined names</i></span> relating to <span><i>restarts</i></span>.</p>
<p>|</p><p><strong>abort invoke-restart-interactively store-value compute-restarts muffle-warning use-value</strong> </p><p><strong>continue restart-bind with-simple-restart find-restart restart-case</strong> </p><p><strong>invoke-restart restart-name</strong></p>|<p></p>
<p>| :- |</p>
<p><strong>Figure 96. Defined names relating to restarts.</strong></p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91423-restart-tests">9.1.4.2.3 Restart Tests<a href="j-b-condition-system-concepts.html#91423-restart-tests" class="hash-link" aria-label="Direct link to 9.1.4.2.3 Restart Tests" title="Direct link to 9.1.4.2.3 Restart Tests"></a></h4>
<!-- -->
<p>Each <span><i>restart</i></span> has an associated test, which is a function of one argument (a <span><i>condition</i></span> or <span><b>nil</b></span>) which returns <span><i>true</i></span> if the <span><i>restart</i></span> should be visible in the current <span><i>situation</i></span>. This test is created by the <!-- -->:test-function<!-- --> option to <span><b>restart-bind</b></span> or the <!-- -->:test<!-- --> option to <span><b>restart-case</b></span>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="91424-associating-a-restart-with-a-condition">9.1.4.2.4 Associating a Restart with a Condition<a href="j-b-condition-system-concepts.html#91424-associating-a-restart-with-a-condition" class="hash-link" aria-label="Direct link to 9.1.4.2.4 Associating a Restart with a Condition" title="Direct link to 9.1.4.2.4 Associating a Restart with a Condition"></a></h4>
<!-- -->
<p>A <span><i>restart</i></span> can be “associated with” a <span><i>condition</i></span> explicitly by <span><b>with-condition-restarts</b></span>, or implicitly by <span><b>restart-case</b></span>. Such an assocation has <span><i>dynamic extent</i></span>.</p>
<p>A single <span><i>restart</i></span> may be associated with several <span><i>conditions</i></span> at the same time. A single <span><i>condition</i></span> may have several associated <span><i>restarts</i></span> at the same time.</p>
<p>Active restarts associated with a particular <span><i>condition</i></span> can be detected by <em>calling</em> a <span><i>function</i></span> such as <span><b>find-restart</b></span>, supplying that <span><i>condition</i></span> as the <em>condition argument</em>. Active restarts can also be detected without regard to any associated <span><i>condition</i></span> by calling such a function without a <em>condition argument</em>, or by supplying a value of <span><b>nil</b></span> for such an <span><i>argument</i></span>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="915-assertions">9.1.5 Assertions<a href="j-b-condition-system-concepts.html#915-assertions" class="hash-link" aria-label="Direct link to 9.1.5 Assertions" title="Direct link to 9.1.5 Assertions"></a></h2>
<!-- -->
<p>Conditional signaling of <span><i>conditions</i></span> based on such things as key match, form evaluation, and <span><i>type</i></span> are handled by assertion <span><i>operators</i></span>. Figure 97 shows <span><i>operators</i></span> relating to assertions.</p>
<p>|</p><p><strong>assert check-type ecase</strong> </p><p><strong>ccase ctypecase etypecase</strong></p>|<p></p>
<p>| :- |</p>
<p><strong>Figure 97. Operators relating to assertions.</strong></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="916-notes-about-the-condition-system">9.1.6 Notes about the Condition System<a href="j-b-condition-system-concepts.html#916-notes-about-the-condition-system" class="hash-link" aria-label="Direct link to 9.1.6 Notes about the Condition System" title="Direct link to 9.1.6 Notes about the Condition System"></a></h2>
<!-- -->
<!-- -->
<p>For a background reference to the abstract concepts detailed in this section, see <em>Exceptional Situations in Lisp</em>. The details of that paper are not binding on this document, but may be helpful in establishing a conceptual basis for understanding this material.</p></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/lisp-docs/cl-language-reference/tree/main/docs/chap-9/j-b-condition-system-concepts.md" target="_blank" rel="noopener noreferrer" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"><span class="theme-last-updated">Last updated<!-- --> by <b>daninus14</b></span></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="../chap-8/intro.html"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">intro</div></a><a class="pagination-nav__link pagination-nav__link--next" href="../category/92-conditions-dictionary.html"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">9.2 Conditions Dictionary</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="j-b-condition-system-concepts.html#911-condition-types" class="table-of-contents__link toc-highlight">9.1.1 Condition Types</a><ul><li><a href="j-b-condition-system-concepts.html#9111-serious-conditions" class="table-of-contents__link toc-highlight">9.1.1.1 Serious Conditions</a></li></ul></li><li><a href="j-b-condition-system-concepts.html#912-creating-conditions" class="table-of-contents__link toc-highlight">9.1.2 Creating Conditions</a><ul><li><a href="j-b-condition-system-concepts.html#9121-condition-designators" class="table-of-contents__link toc-highlight">9.1.2.1 Condition Designators</a></li></ul></li><li><a href="j-b-condition-system-concepts.html#913-printing-conditions" class="table-of-contents__link toc-highlight">9.1.3 Printing Conditions</a><ul><li><a href="j-b-condition-system-concepts.html#9131-recommended-style-in-condition-reporting" class="table-of-contents__link toc-highlight">9.1.3.1 Recommended Style in Condition Reporting</a><ul><li><a href="j-b-condition-system-concepts.html#91311-capitalization-and-punctuation-in-condition-reports" class="table-of-contents__link toc-highlight">9.1.3.1.1 Capitalization and Punctuation in Condition Reports</a></li><li><a href="j-b-condition-system-concepts.html#91312-leading-and-trailing-newlines-in-condition-reports" class="table-of-contents__link toc-highlight">9.1.3.1.2 Leading and Trailing Newlines in Condition Reports</a></li><li><a href="j-b-condition-system-concepts.html#91313-embedded-newlines-in-condition-reports" class="table-of-contents__link toc-highlight">9.1.3.1.3 Embedded Newlines in Condition Reports</a></li><li><a href="j-b-condition-system-concepts.html#91314-note-about-tabs-in-condition-reports" class="table-of-contents__link toc-highlight">9.1.3.1.4 Note about Tabs in Condition Reports</a></li><li><a href="j-b-condition-system-concepts.html#91315-mentioning-containing-function-in-condition-reports" class="table-of-contents__link toc-highlight">9.1.3.1.5 Mentioning Containing Function in Condition Reports</a></li></ul></li></ul></li><li><a href="j-b-condition-system-concepts.html#914-signaling-and-handling-conditions" class="table-of-contents__link toc-highlight">9.1.4 Signaling and Handling Conditions</a><ul><li><a href="j-b-condition-system-concepts.html#9141-signaling" class="table-of-contents__link toc-highlight">9.1.4.1 Signaling</a><ul><li><a href="j-b-condition-system
</body>
</html>