Exceptions: Difference between revisions
Content deleted Content added
→try-catch: langtag |
|||
Line 512:
===Defining exceptions===
Exceptions can only be declared at the "top-level" of a module or interface. Arguments are optional.
<lang modula3>EXCEPTION EndOfFile;
EXCEPTION
===Throw exceptions===
Exceptions can be bound to procedures using RAISES:
<lang modula3>PROCEDURE Foo() RAISES { EndOfFile } =▼
▲PROCEDURE Foo() RAISES { EndOfFile } =
...
RAISE EndOfFile;
...
</
===Catching exceptions===
<lang modula3>TRY
Foo();
EXCEPT
| EndOfFile => HandleFoo();
END;</lang>
Modula-3 also has a FINALLY keyword:
<lang modula3>TRY
Foo();
FINALLY
CleanupFoo(); (* always executed *)
END;
</
=={{header|OCaml}}==
|