1
0
Fork 0
cl-sites/ecl.common-lisp.dev/static/manual/Conditions.html
2024-12-24 19:15:49 +01:00

286 lines
15 KiB
HTML

<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Conditions (ECL Manual)</title>
<meta name="description" content="Conditions (ECL Manual)">
<meta name="keywords" content="Conditions (ECL Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Indexes.html" rel="index" title="Indexes">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Standards.html" rel="up" title="Standards">
<link href="Symbols.html" rel="next" title="Symbols">
<link href="Structures.html" rel="prev" title="Structures">
<style type="text/css">
<!--
/* colors */
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
@media (prefers-color-scheme: dark) {
/* dark theme */
html { color: seashell;
background: #1A1A1A; }
body { background: #1A1A1A; }
th { border-bottom: 2px solid lightgray; }
h1, h2, h3, h4, h5 { background-image: linear-gradient(to left, #202020, #3A3A3A); }
code, var, code a { color: darkorange;
background: #2A2A2A; }
a { color: seashell; }
pre { background: #2A2A2A;
color: seashell;
/* mark longer code block with stripe on the left */
border-left: 5px solid darkorange;
padding-left: 10px; }
pre.screen { background: #2A2A2A;
border: 1px solid lightgray; }
pre.programlisting { background: #2A2A2A;
border-left: 1px solid lightgray;
border-top: 1px solid lightgray; }
/* we need a light background in order for the images to be readable */
img { background: white }
}
@media (prefers-color-scheme: light) {
/* light theme */
html { background: white }
body { background: white }
th { border-bottom: 2px solid gray; }
h1, h2, h3, h4, h5 { background: lightgray; }
code, var, code a { color: darkred;
background: whitesmoke; }
a { color: #000; }
pre { background: whitesmoke;
color: black;
/* mark longer code block with stripe on the left */
border-left: 5px solid darkred;
padding-left: 10px; }
pre.screen { background: #EEE;
border: 1px solid black; }
pre.programlisting { background: #EEEEEE;
border-left: 1px solid black;
border-top: 1px solid black; }
}
body {
margin: 1em 125px 0 10%;
line-height: 1.5em;
padding: 0 2em 1em 2em;
font: 13px Verdana,Arial, sans-serif
}
ul, dd, dl, dt { margin-top: 0; margin-bottom: 0; }
p, code, td, dl, dt {
line-height: 1.5em;
}
table {
font: inherit;
border-collapse: collapse;
}
th, td {
vertical-align: top;
}
h1, h2, h3 { padding-left: 15px; }
h4, h5 { padding-left: 5px; }
code, pre {
font-size: 1em;
font-family: monospace;
}
var {
font-size: 1em;
}
/* links inside code appear the same as the code itself */
code a {
font-weight: normal;
text-decoration: none;
}
/* but get an underline when hovering */
code a:hover {
text-decoration: underline;
}
/* ordinary links appear in bold */
a { font-weight: bold; }
pre.verbatim {
margin: 0 0 0 0;
}
pre {
overflow: auto;
}
pre.screen {
font-weight: bold;
padding: 0.5em;
}
pre.programlisting {
padding: 0.5em;
}
div p { padding: 0 2em }
li p { padding: 0; margin: 0 }
hr { display: none; }
div.funcsynopsis p {
text-indent: -2em;
}
div.variablelist {
padding: 0 2em;
}
.type, .funcsynopsis, .symbol {
font-family: monospace;
}
.type, .symbol, .replaceable {
white-space: nowrap;
}
-->
</style>
</head>
<body lang="en">
<div class="section-level-extent" id="Conditions">
<div class="nav-panel">
<p>
Next: <a href="Symbols.html" accesskey="n" rel="next">Symbols</a>, Previous: <a href="Structures.html" accesskey="p" rel="prev">Structures</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
</div>
<h3 class="section" id="Conditions-1">2.7 Conditions</h3>
<ul class="mini-toc">
<li><a href="Conditions.html#C-Reference-7" accesskey="1">C Reference</a></li>
</ul>
<div class="subsection-level-extent" id="C-Reference-7">
<h4 class="subsection">2.7.1 C Reference</h4>
<a class="anchor" id="ECL_005fHANDLER_005fCASE"></a><a class="index-entry-id" id="index-ECL_005fHANDLER_005fCASE"></a>
<dl class="first-deffn">
<dt class="deffn" id="index-ECL_005fHANDLER_005fCASE-1"><span class="category-def">Macro: </span><span><strong class="def-name">ECL_HANDLER_CASE</strong><a class="copiable-link" href='Conditions.html#index-ECL_005fHANDLER_005fCASE-1'> &para;</a></span></dt>
<dd><p>C macro for <a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/m_hand_1.htm">handler-case</a>
</p>
<p><b class="b">Synopsis</b>
</p>
<div class="example">
<pre class="verbatim">ECL_HANDLER_CASE_BEGIN(env,names) {
} ECL_HANDLER_CASE(n,condition) { {
} ECL_HANDLER_CASE_END;
</pre></div>
<p><b class="b">Description</b>
</p>
<p><code class="code">ECL_HANDLER_CASE_BEGIN</code> runs a block of C code with a set of error handlers bound to the names given by the list <var class="var">names</var>. The subsequent <code class="code"><a class="ref" href="Conditions.html#ECL_005fHANDLER_005fCASE">ECL_HANDLER_CASE</a></code> statements specify what to do when the <var class="var">n</var>-th type of conditions is found, where <var class="var">n</var> is an integer denoting the position of the name in the list <var class="var">names</var>.
</p>
<p>When a condition is signaled, ECL scans the list of signal handlers, looking for matches based on <code class="code">typep</code>. If the match with the highest precedence belongs to the list <var class="var">names</var>, ECL will perform a non-local transfer of control to the appropriate <code class="code"><a class="ref" href="Conditions.html#ECL_005fHANDLER_005fCASE">ECL_HANDLER_CASE</a></code>, passing it a <var class="var">condition</var> object as unique argument.
</p>
<p>The following example shows how to establish a handler for <code class="code">error</code> conditions. Note how the first value to <code class="code"><a class="ref" href="Conditions.html#ECL_005fHANDLER_005fCASE">ECL_HANDLER_CASE</a></code> matches the position of the condition name in the list:
</p>
<div class="example">
<pre class="verbatim">cl_object error = ecl_make_symbol(&quot;ERROR&quot;,&quot;CL&quot;);
ECL_HANDLER_CASE_BEGIN(the_env, ecl_list1(error)) {
/* This form is evaluated with bound handlers */
output = cl_eval(1, form);
} ECL_HANDLER_CASE(1, condition) {
/* This code is executed when an error happens */
/* We just return the error that took place */
output = condition;
} ECL_HANDLER_CASE_END;
</pre></div>
</dd></dl>
<a class="anchor" id="ECL_005fRESTART_005fCASE"></a><a class="index-entry-id" id="index-ECL_005fRESTART_005fCASE"></a>
<dl class="first-deffn">
<dt class="deffn" id="index-ECL_005fRESTART_005fCASE-1"><span class="category-def">Macro: </span><span><strong class="def-name">ECL_RESTART_CASE</strong><a class="copiable-link" href='Conditions.html#index-ECL_005fRESTART_005fCASE-1'> &para;</a></span></dt>
<dd><p>C macro for <a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/m_rst_ca.htm">restart-case</a>
</p>
<p><b class="b">Synopsis</b>
</p>
<div class="example">
<pre class="verbatim">ECL_RESTART_CASE_BEGIN(env,names) {
} ECL_RESTART_CASE(n,args) { {
} ECL_RESTART_CASE_END;
</pre></div>
<p><b class="b">Description</b>
</p>
<p><code class="code">ECL_RESTART_CASE_BEGIN</code> runs a block of C code with a set of restarts bound to the names given by the list <var class="var">names</var>. The subsequent <code class="code"><a class="ref" href="Conditions.html#ECL_005fRESTART_005fCASE">ECL_RESTART_CASE</a></code> statements specify what to do when the <var class="var">n</var>-th restart is invoked, where <var class="var">n</var> is an integer denoting the position of the name in the list <var class="var">names</var>.
</p>
<p>When the restart is invoked, it can receive any number of arguments, which are grouped in a list and stored in a new variable created with the name <var class="var">args</var>.
</p>
<p>The following example shows how to establish an <var class="var">abort</var> and a <var class="var">use-value</var> restart. Note how the first value to <code class="code"><a class="ref" href="Conditions.html#ECL_005fRESTART_005fCASE">ECL_RESTART_CASE</a></code> matches the position of the restart name in the list:
</p>
<div class="example">
<pre class="verbatim">cl_object abort = ecl_make_symbol(&quot;ABORT&quot;,&quot;CL&quot;);
cl_object use_value = ecl_make_symbol(&quot;USE-VALUE&quot;,&quot;CL&quot;);
ECL_RESTART_CASE_BEGIN(the_env, cl_list(2, abort, use_value)) {
/* This form is evaluated with bound restarts */
output = cl_eval(1, form);
} ECL_RESTART_CASE(1, args) {
/* This code is executed when the 1st restart (ABORT) is invoked */
output = ECL_NIL;
} ECL_RESTART_CASE(2, args) {
/* This code is executed when the 2nd restart (USE-VALUE) is invoked */
output = ECL_CAR(args);
} ECL_RESTART_CASE_END;
</pre></div>
</dd></dl>
<ul class="mini-toc">
<li><a href="Conditions.html#ANSI-dictionary" accesskey="1">ANSI dictionary</a></li>
</ul>
<div class="subsubsection-level-extent" id="ANSI-dictionary">
<h4 class="subsubsection">2.7.1.1 ANSI dictionary</h4>
<p>Common Lisp and C equivalence
</p>
<table class="multitable">
<thead><tr><th width="30%">Lisp symbol</th><th width="70%">C function</th></tr></thead>
<tbody><tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_abortc.htm">abort</a></td><td width="70%">cl_object cl_abort(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_break.htm">break</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_cell_e.htm">cell-error-name</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_cerror.htm">cerror</a></td><td width="70%">cl_object cl_cerror(cl_narg narg, cl_object continue_format_control, cl_object datum, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_comp_1.htm">compute-restarts</a></td><td width="70%">cl_object cl_compute_restarts(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_abortc.htm">continue</a></td><td width="70%">cl_object cl_continue(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_error.htm">error</a></td><td width="70%">cl_object cl_error(cl_narg narg, cl_object datum, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_find_r.htm">find-restart</a></td><td width="70%">cl_object cl_find_restart(cl_narg narg, cl_object identifier, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/m_hand_1.htm">handler-case</a></td><td width="70%">ECL_HANDLER_CASE macro</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invali.htm">invalid-method-error</a></td><td width="70%">cl_object cl_invalid_method_error (cl_narg narg, cl_object method, cl_object format, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invoke.htm">invoke-debugger</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invo_1.htm">invoke-restart</a></td><td width="70%">cl_object cl_invoke_restart(cl_narg narg, cl_object restart, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invo_2.htm">invoke-restart-interactively</a></td><td width="70%">cl_object cl_invoke_restart_interactively(cl_object restart)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_mk_cnd.htm">make-condition</a></td><td width="70%">cl_make_condition(cl_narg narg, cl_object type, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_meth_1.htm">method-combination-error</a></td><td width="70%">cl_object cl_method_combination_error(cl_narg narg, cl_object format, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_abortc.htm">muffle-warning</a></td><td width="70%">cl_object cl_muffle_warning(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_rst_na.htm">restart-name</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_rst_ca.htm">restart-case</a></td><td width="70%">ECL_RESTART_CASE macro</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_signal.htm">signal</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_smp_cn.htm">simple-condition-format-control</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_smp_cn.htm">simple-condition-format-arguments</a></td><td width="70%">[Only in Common Lisp]</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_abortc.htm">store-value</a></td><td width="70%">cl_object cl_store_value(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_abortc.htm">use-value</a></td><td width="70%">cl_object cl_use_value(cl_narg narg, ...)</td></tr>
<tr><td width="30%"><a class="url" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_warn.htm">warn</a></td><td width="70%">[Only in Common Lisp]</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Symbols.html" accesskey="n" rel="next">Symbols</a>, Previous: <a href="Structures.html" accesskey="p" rel="prev">Structures</a>, Up: <a href="Standards.html" accesskey="u" rel="up">Standards</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indexes.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>