1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<html><head><title>XLISP errset</title>
<link rel="stylesheet" type="text/css" href="reference.css">
</head>
<body>
<a href="../start.htm">Nyquist / XLISP 2.0</a> -
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>
<hr>
<h1>errset</h1>
<hr>
<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
<tr valign="top">
<td><nobr>Type:</nobr></td>
<td><nobr> - </nobr></td>
<td width="100%"><nobr>special form (fsubr)</nobr></td>
</tr>
<tr valign="top">
<td><nobr>Source:</nobr></td>
<td><nobr> - </nobr></td>
<td width="100%"><nobr>xlcont.c</nobr></td>
</tr>
</tbody></table></p>
<h2>Syntax</h2>
<dl>
<dt>(errset <i>expr</i> [<i>print-flag</i>])</dt>
<dd><i>expr</i> - an expression to be evaluated<br>
<i>print-flag</i> - an optional expression
[<a href="nil.htm">NIL</a> or
non-<a href="nil.htm">NIL</a>]<br>
returns - the value of the last expression
<a href="cons.htm">cons</a>ed with
<nobr><a href="nil.htm">NIL</a> ,</nobr> or
<a href="nil.htm">NIL</a> on error</dd>
</dl>
<h2>Description</h2>
<p>The 'errset' special form is a mechanism that allows the trapping of
errors within the execution of 'expr'.
<a href="global-breakenable.htm">*breakenable*</a> must be set to
<a href="nil.htm">NIL</a> for the 'errset' form to function. If
<a href="global-breakenable.htm">*breakenable*</a> is
<nobr>non-<a href="nil.htm">NIL</a> ,</nobr> the normal break
loop will handle the error. For 'errset', if no error occurs within 'expr',
the value of the last expression is <a href="cons.htm">cons</a>ed
with <a href="nil.htm">NIL</a>. If an error occurs within 'expr',
the error is caught by 'errset' and a <a href="nil.htm">NIL</a>
is returned from 'errset'. If 'print-flag' is
<nobr><a href="nil.htm">NIL</a> ,</nobr> the error message
normally generated by 'expr' will not be printed. If 'print-flag' is
non-<a href="nil.htm">NIL</a> or not present in the 'errset'
form, the error message will be printed.</p>
<p>Errors from <a href="error.htm">error</a> and
<a href="cerror.htm">cerror</a> and system errors
will be handled by 'errset'. Note that the
<a href="cerror.htm">cerror</a> message will only include
the error message portion, not the
<a href="continue.htm">continue</a> message portion.
<a href="break.htm">break</a> is not intercepted by 'errset'.</p>
<h2>Examples</h2>
<pre class="example">
(setq *breakenable* nil) <font color="#008844">; do not enter the break-loop on errors</font>
(errset (error "hi" "ho")) <font color="#008844">; prints error: hi - "ho" returns NIL</font>
(errset (cerror "hi" "ho" "he")) <font color="#008844">; prints error: ho - "he" returns NIL</font>
(errset (error "hey" "ho") NIL) <font color="#008844">; returns NIL</font>
(errset (break "hey")) <font color="#008844">; break: hey - if continued: return from BREAK</font>
(continue) <font color="#008844">; [ continue from break loop ]</font>
(errset (+ 1 5)) <font color="#008844">; returns (6)</font>
(errset (+ 1 "a") NIL) <font color="#008844">; returns NIL</font>
(setq *breakenable* t) <font color="#008844">; re-enable the break-loop on errors</font>
</pre>
<p>How to keep XLISP from signalling an error:</p>
<pre class="example">
(setq *breakenable* nil)
(errset <font color="#0000CC">expression-causing-an-error</font> t) <font color="#008844">; print the error message</font>
(errset <font color="#0000CC">expression-causing-an-error</font>) <font color="#008844">; do NOT print the error message</font>
</pre>
<p><b>Note:</b> Be sure to set
<a href="global-breakenable.htm">*breakenable*</a> to
<a href="nil.htm">NIL</a> before using 'errset' and to
non-<a href="nil.htm">NIL</a> after using 'errset'. <nobr>If you</nobr> don't
reset <nobr><a href="global-breakenable.htm">*breakenable*</a> ,</nobr> no
errors will be reported.</p>
<p>See the
<a href="../manual/xlisp-man-022.htm#errset">errset</a>
function in the <nobr>XLISP 2.0</nobr> manual.</p>
<p><nobr> <a href="#top">Back to Top</nobr></a></p>
<hr>
<a href="../start.htm">Nyquist / XLISP 2.0</a> -
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>
</body></html>
|