Download CDuce Programming Language User`s manual
Transcript
3.4 Exceptions
The following construction raises an exception:
raise e
The result of the evaluation of e is the argument of the exception.
It is possible to catch an exception with an exception handler:
try e with
| p1 -> e1
...
| pn -> en
Whenever the evaluation of e raises an exception, the handler tries to match the
argument of the exception with the patterns (following a first-match policy). If no
pattern matches, the exception is propagated.
Note that contrary to ML, there is no exception name: the only information carried by
the exception is its argument. Consequently, it is the responsibility of the programmer
to put enough information in the argument to recognize the correct exceptions. Note
also that a branch (`A,x) -> e in an exception handler gives no static information
about the capture variable x (its type is Any). Note: it is possible that the support for
exceptions will change in the future to match ML-like named exceptions.
3.5 Record operators
There are three kinds of operators on records:
•
•
•
Field projection:
e.l
where l is the name of a label which must be present in the result of the
evaluation of e. This construction is equivalent to: match e with { l = x }
-> x. It is necessary to put whitespace between the expression and the dot when
the expression is an identifier.
Record concatenation:
e1 + e2
The two expressions must evaluate to records, which are merged together. If both
have a field with the same name, the one on the right have precedence. Note that
the operator + is overloaded: it also operates on integers.
Field suppression:
21