Commit edb1fa6a authored by Pietro Abate's avatar Pietro Abate

[r2005-06-24 11:22:54 by beppe] Empty log message

Original author: beppe
Date: 2005-06-24 11:22:54+00:00
parent bc8567a9
...@@ -270,7 +270,21 @@ variable <code>parents</code> it matches it against the type ...@@ -270,7 +270,21 @@ variable <code>parents</code> it matches it against the type
type <code>ParentBook</code>) then it performs the assignment (the variable type <code>ParentBook</code>) then it performs the assignment (the variable
<code>x</code> is bound to the result of the load_xml expression by the pattern <code>x</code> is bound to the result of the load_xml expression by the pattern
<code>x&amp;ParentBook</code>) otherwise it raises an exception. <code>x&amp;ParentBook</code>) otherwise it raises an exception.
</p>
<p>
Of course an exception such as "parents.xml is not a document of type ParentBook" it is not
very informative about why the document failed the match an where the error might be. In CDuce it is
possible to ask the program to perform this check and raise an informative exception (a string
that describes and localize the problem) by using the dynamic type check construction <code>(%%e%%:?%%t%%)</code> which
checks whether the expression <code>%%exp%%</code> has type <code>%%t%%</code> and it either returns the result of
<code>%%exp%%</code> or raise an informative exception. The dynamic type check can be also used in a let construction as follows
</p>
<sample><![CDATA[
let parents :? ParentBook = load_xml "parents.xml"
]]></sample>
<p>
which does the same test as the previous program but in case of failure give
information to the programmer on the reasons why the type check failed.
</p> </p>
<p> <p>
The command <code>load_xml "parents.xml"</code> is just an abbreviated form for The command <code>load_xml "parents.xml"</code> is just an abbreviated form for
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment