Debian Codegraph @

info/gcl/catch.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>catch (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="catch (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="catch (ANSI and GNU Common Lisp Document)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="Data-and-Control-Flow-Dictionary.html" rel="up" title="Data and Control Flow Dictionary">
15 <link href="go.html" rel="next" title="go">
16 <link href="block.html" rel="prev" title="block">
17 <style type="text/css">
18 <!--
19 a.summary-letter {text-decoration: none}
20 blockquote.indentedblock {margin-right: 0em}
21 div.display {margin-left: 3.2em}
22 div.example {margin-left: 3.2em}
23 div.lisp {margin-left: 3.2em}
24 kbd {font-style: oblique}
25 pre.display {font-family: inherit}
26 pre.format {font-family: inherit}
27 pre.menu-comment {font-family: serif}
28 pre.menu-preformatted {font-family: serif}
29 span.nolinebreak {white-space: nowrap}
30 span.roman {font-family: initial; font-weight: normal}
31 span.sansserif {font-family: sans-serif; font-weight: normal}
32 ul.no-bullet {list-style: none}
33 -->
34 </style>
35
36
37 </head>
38
39 <body lang="en">
40 <span id="catch"></span><div class="header">
41 <p>
42 Next: <a href="go.html" accesskey="n" rel="next">go</a>, Previous: <a href="block.html" accesskey="p" rel="prev">block</a>, Up: <a href="Data-and-Control-Flow-Dictionary.html" accesskey="u" rel="up">Data and Control Flow Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="catch-_005bSpecial-Operator_005d"></span><h4 class="subsection">5.3.23 catch [Special Operator]</h4>
46
47 <p><code>catch</code> <i><i>tag</i> {<i>form</i>}*</i> &rArr; <i>{<i>result</i>}*</i>
48 </p>
49 <span id="Arguments-and-Values_003a_003a-44"></span><h4 class="subsubheading">Arguments and Values::</h4>
50
51 <p><i>tag</i>&mdash;a <i>catch tag</i>; evaluated.
52 </p>
53 <p><i>forms</i>&mdash;an <i>implicit progn</i>.
54 </p>
55 <p><i>results</i>&mdash;if the <i>forms</i> exit normally,
56 the <i>values</i> returned by the <i>forms</i>;
57 if a throw occurs to the <i>tag</i>,
58 the <i>values</i> that are thrown.
59 </p>
60 <span id="Description_003a_003a-76"></span><h4 class="subsubheading">Description::</h4>
61
62 <p><b>catch</b> is used as the destination of a non-local
63 control transfer by <b>throw</b>.
64 <i>Tags</i> are used to find the <b>catch</b>
65 to which a <b>throw</b> is transferring control.
66 <tt>(catch 'foo <i>form</i>)</tt> catches a
67 <tt>(throw 'foo <i>form</i>)</tt> but not a
68 <tt>(throw 'bar <i>form</i>)</tt>.
69 </p>
70 <p>The order of execution of <b>catch</b> follows:
71 <span id="index-order-of-evaluation-3"></span>
72 </p>
73 <span id="index-evaluation-order-3"></span>
74
75 <dl compact="compact">
76 <dt>1.</dt>
77 <dd><p><i>Tag</i> is evaluated.
78 It serves as the name of the
79 <b>catch</b>.
80 </p>
81 </dd>
82 <dt>2.</dt>
83 <dd><p><i>Forms</i> are then evaluated as an implicit <b>progn</b>,
84 and the results of the last <i>form</i> are returned unless a
85 <b>throw</b> occurs.
86 </p>
87 </dd>
88 <dt>3.</dt>
89 <dd><p>If a <b>throw</b> occurs
90 during the execution of one of the <i>forms</i>, control
91 is transferred to the <b>catch</b> <i>form</i> whose <i>tag</i>
92 is <b>eq</b> to
93 the tag argument of the <b>throw</b>
94 and which is the most recently established <b>catch</b> with that
95 <i>tag</i>.
96 No further evaluation of <i>forms</i> occurs.
97 </p>
98 </dd>
99 <dt>4.</dt>
100 <dd><p>The <i>tag</i> <i>established</i>
101 by <b>catch</b> is <i>disestablished</i>
102 just before the results are returned.
103 </p>
104 </dd>
105 </dl>
106
107 <p>If during the execution of one of the <i>forms</i>, a <b>throw</b>
108 is executed whose tag is <b>eq</b> to the <b>catch</b> tag,
109 then the values specified by the <b>throw</b> are
110 returned as the result of the dynamically most recently established
111 <b>catch</b> form with that tag.
112 </p>
113 <p>The mechanism for <b>catch</b> and <b>throw</b> works even
114 if <b>throw</b> is not within the lexical scope of <b>catch</b>.
115 <b>throw</b> must occur within the <i>dynamic extent</i>
116 of the <i>evaluation</i> of the body of a <b>catch</b> with a corresponding <i>tag</i>.
117 </p>
118 <span id="Examples_003a_003a-50"></span><h4 class="subsubheading">Examples::</h4>
119 <div class="example">
120 <pre class="example"> (catch 'dummy-tag 1 2 (throw 'dummy-tag 3) 4) &rArr; 3
121 (catch 'dummy-tag 1 2 3 4) &rArr; 4
122 (defun throw-back (tag) (throw tag t)) &rArr; THROW-BACK
123 (catch 'dummy-tag (throw-back 'dummy-tag) 2) &rArr; T
124
125 ;; Contrast behavior of this example with corresponding example of BLOCK.
126 (catch 'c
127 (flet ((c1 () (throw 'c 1)))
128 (catch 'c (c1) (print 'unreachable))
129 2)) &rArr; 2
130 </pre></div>
131
132 <span id="Exceptional-Situations_003a_003a-15"></span><h4 class="subsubheading">Exceptional Situations::</h4>
133 <p>An error of <i>type</i> <b>control-error</b> is signaled
134 if <b>throw</b> is done
135 when there is no suitable <b>catch</b> <i>tag</i>.
136 </p><span id="See-Also_003a_003a-61"></span><h4 class="subsubheading">See Also::</h4>
137
138 <p><a href="throw.html">throw</a>
139 , <a href="Evaluation.html">Evaluation</a>
140 </p>
141 <span id="Notes_003a_003a-37"></span><h4 class="subsubheading">Notes::</h4>
142
143 <p>It is customary for <i>symbols</i> to be used
144 as <i>tags</i>, but any <i>object</i> is permitted.
145 However, numbers should not be
146 used because the comparison is done using <b>eq</b>.
147 </p>
148 <p><b>catch</b> differs from <b>block</b> in that
149 <b>catch</b>
150 tags have dynamic <i>scope</i> while
151 <b>block</b> names have <i>lexical scope</i>.
152 </p>
153 <hr>
154 <div class="header">
155 <p>
156 Next: <a href="go.html" accesskey="n" rel="next">go</a>, Previous: <a href="block.html" accesskey="p" rel="prev">block</a>, Up: <a href="Data-and-Control-Flow-Dictionary.html" accesskey="u" rel="up">Data and Control Flow Dictionary</a> &nbsp; </p>
157 </div>
158
159
160
161 </body>
162 </html>