805 lines
38 KiB
HTML
805 lines
38 KiB
HTML
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!--
|
|
|
|
Generated from r6rs-lib.tex by tex2page, v 20070803
|
|
(running on MzScheme 371, unix),
|
|
(c) Dorai Sitaram,
|
|
http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html
|
|
|
|
-->
|
|
<head>
|
|
<title>
|
|
r6rs-lib
|
|
</title>
|
|
<link rel="stylesheet" type="text/css" href="r6rs-lib-Z-S.css" title=default>
|
|
<meta name=robots content="index,follow">
|
|
</head>
|
|
<body>
|
|
<div id=slidecontent>
|
|
<div align=right class=navigation>[Go to <span><a href="r6rs-lib.html">first</a>, <a href="r6rs-lib-Z-H-7.html">previous</a></span><span>, <a href="r6rs-lib-Z-H-9.html">next</a></span> page<span>; </span><span><a href="r6rs-lib-Z-H-1.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-lib-Z-H-21.html#node_index_start">index</a></span>]</div>
|
|
<p></p>
|
|
<a name="node_chap_7"></a>
|
|
<h1 class=chapter>
|
|
<div class=chapterheading><a href="r6rs-lib-Z-H-1.html#node_toc_node_chap_7">Chapter 7</a></div><br>
|
|
<a href="r6rs-lib-Z-H-1.html#node_toc_node_chap_7">Exceptions and conditions</a></h1>
|
|
<p></p>
|
|
<p>
|
|
Scheme allows programs to deal with exceptional situations using two
|
|
cooperating facilities: The exception system for raising and handling
|
|
exceptional situations, and the condition system for describing these
|
|
situations.</p>
|
|
<p>
|
|
The exception system allows the program, when it detects an
|
|
exceptional situation, to pass control to an exception handler, and
|
|
to dynamically establish such exception handlers. Exception
|
|
handlers are always invoked with an object describing the exceptional
|
|
situation. Scheme’s condition system provides a standardized taxonomy
|
|
of such descriptive objects, as well as a facility for extending the
|
|
taxonomy.</p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_7.1"></a>
|
|
<h2 class=section><a href="r6rs-lib-Z-H-1.html#node_toc_node_sec_7.1">7.1 Exceptions</a></h2>
|
|
<p>
|
|
<a name="node_idx_362"></a></p>
|
|
<p>
|
|
This section describes Scheme’s exception-handling and
|
|
exception-raising constructs provided by the <tt>(rnrs exceptions (6))</tt><a name="node_idx_364"></a>library.</p>
|
|
<p>
|
|
Exception handlers are one-argument procedures that determine the
|
|
action the program takes when an exceptional situation is signalled.
|
|
The system implicitly maintains a current exception handler.</p>
|
|
<p>
|
|
<a name="node_idx_366"></a>The program raises an exception
|
|
by invoking the current exception handler, passing it an object
|
|
encapsulating information about the exception. Any procedure accepting
|
|
one argument may serve as an exception handler and any object may be
|
|
used to represent an exception.</p>
|
|
<p>
|
|
The system maintains the current exception handler as part of the
|
|
dynamic environment of the program; see report
|
|
section on “Dynamic extent and
|
|
dynamic environment”.</p>
|
|
<p>
|
|
When a program begins its execution, the current
|
|
exception handler is expected to handle all <tt>&serious</tt>
|
|
conditions by interrupting execution, reporting that an
|
|
exception has been raised, and displaying information
|
|
about the condition object that was provided. The handler
|
|
may then exit, or may provide a choice of other options.
|
|
Moreover, the exception handler is expected to return when
|
|
passed any other non-<tt>&serious</tt> condition.
|
|
Interpretation of these expectations necessarily depends
|
|
upon the nature of the system in which programs are executed,
|
|
but the intent is that users perceive the raising of an
|
|
exception as a controlled escape from the situation that
|
|
raised the exception, not as a crash.</p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_368"></a>with-exception-handler<i> <i>handler</i> <i>thunk</i></i>)</tt> procedure </div>
|
|
<p>
|
|
<i>Handler</i> must be a procedure and should accept one argument.
|
|
<i>Thunk</i> must be a procedure that accepts zero arguments. The <tt>with-exception-handler</tt> procedure returns the results of invoking
|
|
<i>thunk</i>. <i>Handler</i> is installed as the current
|
|
exception handler for the dynamic extent (as determined by <tt>dynamic-wind</tt>) of the invocation of <i>thunk</i>.</p>
|
|
<p>
|
|
<em>Implementation responsibilities: </em>The implementation must check the restrictions on
|
|
<i>handler</i> to the extent performed by applying it as described
|
|
when it is called as a result of a call to <tt>raise</tt> or <tt>raise-continuable</tt>.
|
|
An
|
|
implementation may check whether <i>handler</i> is an appropriate argument
|
|
before applying it.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(guard (<variable></tt> syntax </div>
|
|
|
|
<tt> <cond clause<sub>1</sub>> <cond clause<sub>2</sub>> <tt>...</tt>)<br>
|
|
|
|
<body>)</tt><br>
|
|
<div align=left><tt>=></tt> auxiliary syntax </div>
|
|
|
|
<div align=left><tt>else</tt> auxiliary syntax </div>
|
|
|
|
<a name="node_idx_370"></a><a name="node_idx_372"></a><a name="node_idx_374"></a><p>
|
|
<em>Syntax: </em>Each <cond clause> is as in the specification of <tt>cond</tt>.
|
|
(See report section on “Derived conditionals”.)
|
|
<tt>>^</tt> and <tt>else</tt> are the same as in the <tt>(rnrs base (6))</tt> library.</p>
|
|
<p>
|
|
<em>Semantics: </em>Evaluating a <tt>guard</tt> form evaluates <body> with an exception
|
|
handler that binds the raised object to <variable> and within the scope of
|
|
that binding evaluates the clauses as if they were the clauses of a
|
|
<tt>cond</tt> expression. That implicit <tt>cond</tt> expression is evaluated with the
|
|
continuation and dynamic environment of the <tt>guard</tt> expression. If every
|
|
<cond clause>’s <test> evaluates to <tt>#f</tt> and there
|
|
is no <tt>else</tt> clause, then
|
|
<tt>raise</tt> is re-invoked on the raised object within the dynamic
|
|
environment of the original call to <tt>raise</tt> except that the current
|
|
exception handler is that of the <tt>guard</tt> expression. </p>
|
|
<p>
|
|
The final expression in a <cond> clause is in a tail context if
|
|
the <tt>guard</tt> expression itself is.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_376"></a>raise<i> <i>obj</i></i>)</tt> procedure </div>
|
|
<p>
|
|
Raises a non-continuable exception by invoking the current exception
|
|
handler on <i>obj</i>. The handler is called with a continuation whose
|
|
dynamic environment is that of the call to <tt>raise</tt>, except that
|
|
the current exception handler is the one that was in place when the handler being
|
|
called was installed. When the handler returns, a non-continuable
|
|
exception with condition type <tt>&non-continuable</tt> is raised in the
|
|
same dynamic environment as the handler.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_378"></a>raise-continuable<i> <i>obj</i></i>)</tt> procedure </div>
|
|
<p>
|
|
Raises a <a name="node_idx_380"></a><em>continuable exception</em> by invoking the current exception
|
|
handler on <i>obj</i>. The handler is called with a continuation that
|
|
is equivalent to the continuation of the call to <tt>raise-continuable</tt>, with these two exceptions: (1) the current
|
|
exception handler is the one that was in place
|
|
when the handler being called was installed, and
|
|
(2) if the handler being called returns, then it will again become the
|
|
current exception handler. If the handler returns, the values it
|
|
returns become the values returned by the call to
|
|
<tt>raise-continuable</tt>.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(guard (con<br>
|
|
((error? con)<br>
|
|
(if (message-condition? con)<br>
|
|
(display (condition-message con))<br>
|
|
(display "an error has occurred"))<br>
|
|
’error)<br>
|
|
((violation? con)<br>
|
|
(if (message-condition? con)<br>
|
|
(display (condition-message con))<br>
|
|
(display "the program has a bug"))<br>
|
|
’violation))<br>
|
|
(raise<br>
|
|
(condition<br>
|
|
(make-error)<br>
|
|
(make-message-condition "I am an error"))))<br>
|
|
<i> prints:</i> I am an error<br>
|
|
⇒ error<br>
|
|
<br>
|
|
(guard (con<br>
|
|
((error? con)<br>
|
|
(if (message-condition? con)<br>
|
|
(display (condition-message con))<br>
|
|
(display "an error has occurred"))<br>
|
|
’error))<br>
|
|
(raise<br>
|
|
(condition<br>
|
|
(make-violation<br>
|
|
(make-message-condition "I am an error"))))<br>
|
|
⇒ <tt> &violation</tt> <i>exception</i><br>
|
|
<br>
|
|
(guard (con<br>
|
|
((error? con)<br>
|
|
(display "error opening file")<br>
|
|
<tt>#f</tt>))<br>
|
|
(call-with-input-file "foo.scm" read))<br>
|
|
<i> prints:</i> error opening file<br>
|
|
⇒ <tt>#f</tt><br>
|
|
<br>
|
|
(with-exception-handler<br>
|
|
(lambda (con)<br>
|
|
(cond<br>
|
|
((not (warning? con))<br>
|
|
(raise con))<br>
|
|
((message-condition? con)<br>
|
|
(display (condition-message con)))<br>
|
|
(else<br>
|
|
(display "a warning has been issued")))<br>
|
|
42)<br>
|
|
(lambda ()<br>
|
|
(+ (raise-continuable<br>
|
|
(condition<br>
|
|
(make-warning)<br>
|
|
(make-message-condition<br>
|
|
"should be a number")))<br>
|
|
23)))<br>
|
|
<i> prints:</i> should be a number<br>
|
|
⇒ 65<br>
|
|
<p></tt></p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_7.2"></a>
|
|
<h2 class=section><a href="r6rs-lib-Z-H-1.html#node_toc_node_sec_7.2">7.2 Conditions</a></h2>
|
|
<p></p>
|
|
<p>
|
|
The section describes Scheme’s <tt>(rnrs conditions (6))</tt><a name="node_idx_382"></a>library
|
|
for creating and inspecting
|
|
condition types and values. A condition value encapsulates information
|
|
about an exceptional situation<a name="node_idx_384"></a>.
|
|
Scheme also defines a
|
|
number of basic condition types.</p>
|
|
<p>
|
|
Scheme conditions provides two mechanisms to enable communication
|
|
about an exceptional situation: subtyping among condition types allows
|
|
handling code to determine the general nature of an exception even
|
|
though it does not anticipate its exact nature, and compound
|
|
conditions allow an exceptional situation to be described in multiple
|
|
ways.</p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_7.2.1"></a>
|
|
<h3 class=section><a href="r6rs-lib-Z-H-1.html#node_toc_node_sec_7.2.1">7.2.1 Condition objects</a></h3>
|
|
<p>Conceptually, there are two different kinds of condition objects:
|
|
<i>simple conditions</i><a name="node_idx_386"></a>and
|
|
<i>compound conditions</i><a name="node_idx_388"></a>. An object
|
|
that is either a simple condition or a compound condition is
|
|
simply a <a name="node_idx_390"></a><em>condition</em>. Compound conditions form a type disjoint
|
|
from the base types described in report
|
|
section on “Base types”. A simple condition
|
|
describes a single aspect of an exceptional situation. A compound
|
|
condition represents multiple aspects of an exceptional situation as a
|
|
list of simple conditions, its <i>components</i>. Most of the
|
|
operations described in this section treat a simple condition
|
|
identically to a compound condition with itself as its own sole component. For a
|
|
subtype <i>t</i> of <tt>&condition</tt>, a <i>condition of type
|
|
<i>t</i></i> is either a record of type <i>t</i> or a compound condition
|
|
containing a component of type <i>t</i>.</p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_392"></a></p>
|
|
<div align=left><tt><tt>&condition</tt></tt> condition type </div>
|
|
<p>
|
|
Simple conditions are records of subtypes of the <tt>&condition</tt>
|
|
record type. The <tt>&condition</tt> type has no fields and is neither sealed nor opaque.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_394"></a>condition<i> <i>condition<sub>1</sub></i> <tt>...</tt></i>)</tt> procedure </div>
|
|
<p>
|
|
The <tt>condition</tt>
|
|
procedure returns a condition object with the components of the
|
|
<i>condition</i>s as its components, in the same order, i.e., with the
|
|
components of <i>condition<sub>1</sub></i> appearing first in the same order as in
|
|
<i>condition<sub>1</sub></i>, then with the components of <i>condition<sub>2</sub></i>, and so on. The
|
|
returned condition is compound if the total number of components is
|
|
zero or greater than one. Otherwise, it may be compound or simple.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_396"></a>simple-conditions<i> condition</i>)</tt> procedure </div>
|
|
<p>
|
|
The <tt>simple-conditions</tt>
|
|
procedure returns a list of the components of <i>condition</i>, in the same
|
|
order as they appeared in the construction of <i>condition</i>. The
|
|
returned list is immutable. If the returned list is modified, the
|
|
effect on <i>condition</i> is unspecified.</p>
|
|
<p>
|
|
</p>
|
|
<blockquote><em>Note: </em>
|
|
Because <tt>condition</tt> decomposes its arguments into simple
|
|
conditions, <tt>simple-conditions</tt> always returns a “flattened”
|
|
list of simple conditions.
|
|
</blockquote>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_398"></a>condition?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
Returns <tt>#t</tt> if <i>obj</i> is a (simple or compound) condition,
|
|
otherwise returns <tt>#f</tt>.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_400"></a>condition-predicate<i> rtd</i>)</tt> procedure </div>
|
|
<p>
|
|
<i>Rtd</i> must be a record-type descriptor of a subtype of
|
|
<tt>&condition</tt>. The <tt>condition-predicate</tt> procedure returns
|
|
a procedure that takes one argument. This procedure returns
|
|
<tt>#t</tt> if its argument is a condition of the condition type
|
|
represented by <i>rtd</i>, i.e., if it is either a simple condition of
|
|
that record type (or one of its subtypes) or a compound conditition
|
|
with such a simple condition as one of its components, and <tt>#f</tt>
|
|
otherwise.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(<a name="node_idx_402"></a>condition-accessor<i> rtd proc</i>)</tt> procedure </div>
|
|
<p>
|
|
<i>Rtd</i> must be a record-type descriptor of a subtype of
|
|
<tt>&condition</tt>. <i>Proc</i> should accept
|
|
one argument, a record of the record type of <i>rtd</i>. The <tt>condition-accessor</tt> procedure returns a procedure that accepts a
|
|
single argument, which must be a condition of the type represented by
|
|
<i>rtd</i>. This procedure extracts the first component of the
|
|
condition of the type represented by <i>rtd</i>, and returns the result
|
|
of applying <i>proc</i> to that component.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define-record-type (&cond1 make-cond1 real-cond1?)<br>
|
|
(parent &condition)<br>
|
|
(fields<br>
|
|
(immutable x real-cond1-x)))<br>
|
|
<br>
|
|
(define cond1?<br>
|
|
(condition-predicate<br>
|
|
(record-type-descriptor &cond1)))<br>
|
|
(define cond1-x<br>
|
|
(condition-accessor<br>
|
|
(record-type-descriptor &cond1)<br>
|
|
real-cond1-x))<br>
|
|
<br>
|
|
(define foo (make-cond1 ’foo))<br>
|
|
<br>
|
|
(condition? foo) ⇒ <tt>#t</tt><br>
|
|
(cond1? foo) ⇒ <tt>#t</tt><br>
|
|
(cond1-x foo) ⇒ foo<br>
|
|
<br>
|
|
(define-record-type (&cond2 make-cond2 real-cond2?)<br>
|
|
(parent &condition)<br>
|
|
(fields<br>
|
|
(immutable y real-cond2-y)))<br>
|
|
<br>
|
|
(define cond2?<br>
|
|
(condition-predicate<br>
|
|
(record-type-descriptor &cond2)))<br>
|
|
(define cond2-y<br>
|
|
(condition-accessor<br>
|
|
(record-type-descriptor &cond2)<br>
|
|
real-cond2-y))<br>
|
|
<br>
|
|
(define bar (make-cond2 ’bar))<br>
|
|
<br>
|
|
(condition? (condition foo bar)) <br> ⇒ <tt>#t</tt><br>
|
|
(cond1? (condition foo bar)) <br> ⇒ <tt>#t</tt><br>
|
|
(cond2? (condition foo bar)) <br> ⇒ <tt>#t</tt><br>
|
|
(cond1? (condition foo)) ⇒ <tt>#t</tt><br>
|
|
(real-cond1? (condition foo)) <br> ⇒ <i>unspecified</i><br>
|
|
(real-cond1? (condition foo bar)) <br> ⇒ <tt>#f</tt><br>
|
|
(cond1-x (condition foo bar) <br> ⇒ foo<br>
|
|
(cond2-y (condition foo bar) <br> ⇒ bar<br>
|
|
<br>
|
|
(equal? (simple-conditions (condition foo bar))<br>
|
|
(list foo bar)) ⇒ <tt>#t</tt><br>
|
|
<br>
|
|
(equal? (simple-conditions<br>
|
|
(condition foo (condition bar)))<br>
|
|
(list foo bar)) ⇒ <tt>#t</tt><p></tt></p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div align=left><tt>(define-condition-type <condition-type></tt> syntax </div>
|
|
|
|
<tt><br>
|
|
|
|
<supertype><br>
|
|
|
|
<constructor> <predicate><br>
|
|
|
|
<field-spec<sub>1</sub>> <tt>...</tt>)</tt>
|
|
<a name="node_idx_404"></a><p>
|
|
<em>Syntax: </em><Condition-type>, <supertypes>,
|
|
<constructor>, and <predicate> must all be identifiers.
|
|
Each <field-spec> must be of the form
|
|
</p>
|
|
|
|
<tt>(<field> <accessor>)<p></tt>
|
|
where both <field> and <accessor> must be identifiers.</p>
|
|
<p>
|
|
<em>Semantics: </em>The <tt>define-condition-type</tt> form expands into a record-type
|
|
definition for a record type <condition-type> (see
|
|
section <a href="r6rs-lib-Z-H-7.html#node_sec_6.2">6.2</a>). The record type will be
|
|
non-opaque, non-sealed, and its fields will be immutable.
|
|
It will have <supertype> has its parent type. The remaining
|
|
identifiers will be bound as follows:
|
|
</p>
|
|
<p>
|
|
</p>
|
|
<ul><p>
|
|
</p>
|
|
<li><p><Constructor> is bound to a default constructor for the
|
|
type (see section <a href="r6rs-lib-Z-H-7.html#node_sec_6.3">6.3</a>): It accepts one
|
|
argument for each of the record type’s complete set of fields
|
|
(including parent types, with the fields of the parent coming before
|
|
those of the extension in the arguments) and returns a condition
|
|
object initialized to those arguments.</p>
|
|
<p>
|
|
</p>
|
|
<li><p><Predicate> is bound to a predicate that identifies
|
|
conditions of type <condition-type> or any of its
|
|
subtypes.</p>
|
|
<p>
|
|
</p>
|
|
<li><p>Each <accessor> is bound to a procedure that extracts the
|
|
corresponding field from a condition of type <condition-type>.
|
|
</p>
|
|
</ul><p>
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define-condition-type &c &condition<br>
|
|
make-c c?<br>
|
|
(x c-x))<br>
|
|
<br>
|
|
(define-condition-type &c1 &c<br>
|
|
make-c1 c1?<br>
|
|
(a c1-a))<br>
|
|
<br>
|
|
(define-condition-type &c2 &c<br>
|
|
make-c2 c2?<br>
|
|
(b c2-b))<p></tt></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define v1 (make-c1 "V1" "a1"))<br>
|
|
<br>
|
|
(c? v1) ⇒ <tt>#t</tt><br>
|
|
(c1? v1) ⇒ <tt>#t</tt><br>
|
|
(c2? v1) ⇒ <tt>#f</tt><br>
|
|
(c-x v1) ⇒ "V1"<br>
|
|
(c1-a v1) ⇒ "a1"<p></tt></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define v2 (make-c2 "V2" "b2"))<br>
|
|
<br>
|
|
(c? v2) ⇒ <tt>#t</tt><br>
|
|
(c1? v2) ⇒ <tt>#f</tt><br>
|
|
(c2? v2) ⇒ <tt>#t</tt><br>
|
|
(c-x v2) ⇒ "V2"<br>
|
|
(c2-b v2) ⇒ "b2"<p></tt></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define v3 (condition<br>
|
|
(make-c1 "V3/1" "a3")<br>
|
|
(make-c2 "V3/2" "b3")))<br>
|
|
<br>
|
|
(c? v3) ⇒ <tt>#t</tt><br>
|
|
(c1? v3) ⇒ <tt>#t</tt><br>
|
|
(c2? v3) ⇒ <tt>#t</tt><br>
|
|
(c-x v3) ⇒ "V3/1"<br>
|
|
(c1-a v3) ⇒ "a3"<br>
|
|
(c2-b v3) ⇒ "b3"<p></tt></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define v4 (condition v1 v2))<br>
|
|
<br>
|
|
(c? v4) ⇒ <tt>#t</tt><br>
|
|
(c1? v4) ⇒ <tt>#t</tt><br>
|
|
(c2? v4) ⇒ <tt>#t</tt><br>
|
|
(c-x v4) ⇒ "V1"<br>
|
|
(c1-a v4) ⇒ "a1"<br>
|
|
(c2-b v4) ⇒ "b2"<p></tt></p>
|
|
<p>
|
|
</p>
|
|
|
|
<tt>(define v5 (condition v2 v3))<br>
|
|
<br>
|
|
(c? v5) ⇒ <tt>#t</tt><br>
|
|
(c1? v5) ⇒ <tt>#t</tt><br>
|
|
(c2? v5) ⇒ <tt>#t</tt><br>
|
|
(c-x v5) ⇒ "V2"<br>
|
|
(c1-a v5) ⇒ "a3"<br>
|
|
(c2-b v5) ⇒ "b2"<p></tt></p>
|
|
<p>
|
|
</p>
|
|
<a name="node_sec_7.3"></a>
|
|
<h2 class=section><a href="r6rs-lib-Z-H-1.html#node_toc_node_sec_7.3">7.3 Standard condition types</a></h2>
|
|
<p></p>
|
|
<a name="node_fig_Temp_2"></a>
|
|
<div class=figure align=left><table width=100%><tr><td align=left>
|
|
|
|
|
|
<img src="r6rs-lib-Z-G-3.gif" border="0" alt="[r6rs-lib-Z-G-3.gif]">
|
|
|
|
</td></tr>
|
|
<tr><td align=left><b>Figure 1:</b> Hierarchy of standard condition types</td></tr>
|
|
<tr><td>
|
|
|
|
</td></tr></table></div><p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_406"></a></p>
|
|
<div align=left><tt><tt>&message</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_408"></a>make-message-condition<i> message</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_410"></a>message-condition?<i> obj</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_412"></a>condition-message<i> condition</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &message &condition<br>
|
|
make-message-condition message-condition?<br>
|
|
(message condition-message))<p></tt>
|
|
It carries a message further describing the nature of the condition to
|
|
humans.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_414"></a></p>
|
|
<div align=left><tt><tt>&warning</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_416"></a>make-warning<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_418"></a>warning?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &warning &condition<br>
|
|
make-warning warning?)<p></tt>
|
|
This type describes conditions that do not, in
|
|
principle, prohibit immediate continued execution of the program, but
|
|
may interfere with the program’s execution later.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_420"></a></p>
|
|
<div align=left><tt><tt>&serious</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_422"></a>make-serious-condition<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_424"></a>serious-condition?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &serious &condition<br>
|
|
make-serious-condition serious-condition?)<p></tt></p>
|
|
<p>
|
|
This type describes conditions serious enough that they cannot safely
|
|
be ignored. This condition type is primarily intended as a supertype
|
|
of other condition types.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_426"></a></p>
|
|
<div align=left><tt><tt>&error</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_428"></a>make-error<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_430"></a>error?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &error &serious<br>
|
|
make-error error?)<p></tt>
|
|
This type describes errors, typically caused by something that
|
|
has gone wrong in the interaction of the program with the external
|
|
world or the user.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_432"></a></p>
|
|
<div align=left><tt><tt>&violation</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_434"></a>make-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_436"></a>violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &violation &serious<br>
|
|
make-violation violation?)<p></tt>
|
|
This type describes violations of the language standard or a
|
|
library standard, typically caused by a programming error.
|
|
</p>
|
|
<p> </p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_438"></a></p>
|
|
<div align=left><tt><tt>&assertion</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_440"></a>make-assertion-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_442"></a>assertion-violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &assertion &violation<br>
|
|
make-assertion-violation assertion-violation?)<p></tt>
|
|
This type describes an invalid call to a procedure, either passing an
|
|
invalid number of arguments, or passing an argument of the wrong type.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_444"></a></p>
|
|
<div align=left><tt><tt>&irritants</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_446"></a>make-irritants-condition<i> irritants</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_448"></a>irritants-condition?<i> obj</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_450"></a>condition-irritants<i> condition</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &irritants &condition<br>
|
|
make-irritants-condition irritants-condition?<br>
|
|
(irritants condition-irritants))<p></tt>
|
|
<i>Irritants</i> should be a list of objects. This
|
|
condition provides additional information about a condition, typically
|
|
the argument list of a procedure that detected an exception.
|
|
Conditions of this type are created by the <tt>error</tt> and <tt>assertion-violation</tt> procedures of report
|
|
section on “Errors and violations”.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_452"></a></p>
|
|
<div align=left><tt><tt>&who</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_454"></a>make-who-condition<i> who</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_456"></a>who-condition?<i> obj</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_458"></a>condition-who<i> condition</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &who &condition<br>
|
|
make-who-condition who-condition?<br>
|
|
(who condition-who))<p></tt>
|
|
<i>Who</i> should be a symbol or string identifying the
|
|
entity reporting the exception.
|
|
Conditions of this type are created by the <tt>error</tt> and <tt>assertion-violation</tt> procedures (report
|
|
section on “Errors and violations”), and
|
|
the <tt>syntax-violation</tt> procedure
|
|
(section on “Syntax violations”).
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_460"></a></p>
|
|
<div align=left><tt><tt>&non-continuable</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_462"></a>make-non-continuable-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_464"></a>non-continuable-violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &non-continuable &violation<br>
|
|
make-non-continuable-violation<br>
|
|
non-continuable-violation?)<p></tt>
|
|
This type indicates that an exception handler invoked via
|
|
<tt>raise</tt> has returned.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_466"></a></p>
|
|
<div align=left><tt><tt>&implementation-restriction</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_468"></a>make-implementation-restriction-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_470"></a>implementation-restriction-violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &implementation-restriction<br>
|
|
&violation<br>
|
|
make-implementation-restriction-violation<br>
|
|
implementation-restriction-violation?)<p></tt>
|
|
This type describes a violation of an implementation restriction
|
|
allowed by the specification, such as the absence of representations
|
|
for NaNs and infinities. (See section <a href="r6rs-lib-Z-H-12.html#node_sec_11.3">11.3</a>.)
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_472"></a></p>
|
|
<div align=left><tt><tt>&lexical</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_474"></a>make-lexical-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_476"></a>lexical-violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &lexical &violation<br>
|
|
make-lexical-violation lexical-violation?)<p></tt>
|
|
This type describes syntax violations at the level of the datum syntax.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_478"></a></p>
|
|
<div align=left><tt><tt>&syntax</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_480"></a>make-syntax-violation<i> form subform</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_482"></a>syntax-violation?<i> obj</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_484"></a>syntax-violation-form<i> condition</i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_486"></a>syntax-violation-subform<i> condition</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &syntax &violation<br>
|
|
make-syntax-violation syntax-violation?<br>
|
|
(form syntax-violation-form)<br>
|
|
(subform syntax-violation-subform))<p></tt></p>
|
|
<p>
|
|
This type describes syntax violations.
|
|
<i>Form</i> should be the erroneous syntax object or a
|
|
datum representing the code of the erroneous form. <i>Subform</i>
|
|
should be an optional syntax object or
|
|
datum within the erroneous form that more precisely locates the
|
|
violation. It can be <tt>#f</tt> to indicate the absence of more precise
|
|
information.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p><a name="node_idx_488"></a></p>
|
|
<div align=left><tt><tt>&undefined</tt></tt> condition type </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_490"></a>make-undefined-violation<i></i>)</tt> procedure </div>
|
|
|
|
<div align=left><tt>(<a name="node_idx_492"></a>undefined-violation?<i> obj</i>)</tt> procedure </div>
|
|
<p>
|
|
This condition type could be defined by
|
|
</p>
|
|
|
|
<tt>(define-condition-type &undefined &violation<br>
|
|
make-undefined-violation undefined-violation?)<p></tt>
|
|
This type describes unbound identifiers in the program.
|
|
</p>
|
|
<p></p>
|
|
<p>
|
|
</p>
|
|
<p>
|
|
</p>
|
|
<p></p>
|
|
<div class=smallskip></div>
|
|
<p style="margin-top: 0pt; margin-bottom: 0pt">
|
|
<div align=right class=navigation>[Go to <span><a href="r6rs-lib.html">first</a>, <a href="r6rs-lib-Z-H-7.html">previous</a></span><span>, <a href="r6rs-lib-Z-H-9.html">next</a></span> page<span>; </span><span><a href="r6rs-lib-Z-H-1.html#node_toc_start">contents</a></span><span><span>; </span><a href="r6rs-lib-Z-H-21.html#node_index_start">index</a></span>]</div>
|
|
</p>
|
|
<p></p>
|
|
</div>
|
|
</body>
|
|
</html>
|