VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>VDM</strong>-<strong>10</strong> <strong>Language</strong> <strong>Manual</strong><br />
✡✝<br />
Example : () ==> int<br />
Example () ==<br />
tixe<br />
{ |-> return -1,<br />
|-> DoCommand(),<br />
err |-> return -2 }<br />
in<br />
DoCommand()<br />
✆<br />
In operation DoCommand we use the always statement in the allocation of memory, and all<br />
exceptions raised are captured by the recursive trap statement in operation Example. An<br />
exception with value results in a return value of -1 and no exception raised. If<br />
the value of the exception is we try to perform the operation DoCommand again.<br />
If this raises an exception, this is also handled by the recursive trap statement. All other<br />
exceptions result in the return of the value -2.<br />
13.12 The Error Statement<br />
Syntax: statement = . . .<br />
| error statement<br />
| . . . ;<br />
error statement = ‘error’ ;<br />
Semantics: The error statement corresponds to the undefined expression. It is used to state explicitly<br />
that the result of a statement is undefined and because of this an error has occurred.<br />
When an error statement is evaluated the interpreter will terminate the execution of the specification<br />
and report that an error statement was evaluated.<br />
Pragmatically use of error statements differs from pre-conditions as was the case with undefined<br />
expressions: use of a pre-condition means it is the caller’s responsibility to ensure that<br />
the pre-condition is satisfied when the operation is called; if an error statement is used it is<br />
the called operation’s responsibility to deal with error handling.<br />
Examples: The operation SquareRoot on page <strong>10</strong>9 does not exclude the possibility that the<br />
number to be square rooted might be negative. We remedy this in the operation SquareRootErr:<br />
✞<br />
SquareRootErr : real * real ==> real<br />
SquareRootErr (r,e) ==<br />
if r < 0<br />
then error<br />
118