Success or Failure
Writing a program could be easily be described as just putting the next step
after the other as long as things go well. It is when things are not going well
('fail'), that other actions are needed. Ocean supports three levels
- 'fail', which means that a step did not succeed, but that this was to
expected. All relation symbols use this strategy: the point of comparing 2
entities is that you expect them not to have a certain realtion
from time to time.
'fail' does not know a reason, because in the context there could be only one.
- 'error', which means that a step did not succeed, but that this should not
happen during a normal program run. Failure to allocate a resource is one of
the more common errors. An 'error' can report in a special Integer
value or a String (or both). Usually such error can be handled locally,
even if that entails calling exitProgram().
- 'exception', which means that a step did not succeed and that it is not
expected that the immediate caller can do anything about it, or that the
handling of the failure needs additional information.
foo ::= bar
try ::= try
catch ::= catch
retry ::= retry
finally ::= finally
try-part ::= try [s] spec [s] [code]...
catch-part ::= catch s class-id [s] spec [s] [code]...
finally-part ::= finally [s] spec [s] [code]...
handled-code ::= try-part catch-part... [finally-part] end [try]
The list of exceptions a fn can throw is part of the 'contract'
Exceptions are run in lexical scope where the catch is
implemented, but functionaly they are called as a subroutine by raise.
This means that the stack has not yet been rewound, so that a 'return' to the
function raising the expection is possible. This is done by retry().