Anonymous user
Exceptions: Difference between revisions
Modula-3
(started ruby) |
(Modula-3) |
||
Line 481:
make -f fail.mk; exit 0
=={{header|Modula-3}}==
===Defining exceptions===
Exceptions can only be declared at the "top-level" of a module or interface. Arguments are optional.
<pre>
EXCEPTION EndOfFile;
EXCEPTION Error(TEXT);
</pre>
===Throw exceptions===
Exceptions can be bound to procedures using RAISES:
<pre>
PROCEDURE Foo() RAISES { EndOfFile } =
...
RAISE EndOfFile;
...
</pre>
===Catching exceptions===
<pre>
TRY
Foo();
EXCEPT
EndOfFile => HandleFoo();
END;
</pre>
Modula-3 also has a FINALLY keyword:
<pre>
TRY
Foo();
FINALLY
CleanupFoo(); (* always executed *)
END;
</pre>
=={{header|OCaml}}==
|