try and otherwise
try runs a block; if something in it fails, otherwise handles it.
Try and Otherwise
Otter uses:
Output
try
...
otherwise
...
.
for error handling.
Example:
Otter
try
read "settings.json" into settings
otherwise
say "Could not load settings."
.
If the try body completes normally, the otherwise body does not run.
If an operation in the try body fails, Otter runs the otherwise body.
Otherwise Is Optional for Try
A try block may exist without an otherwise body when the runtime or surrounding code handles the failure.
Otter
try
read "settings.json" into settings
.
The exact propagation behavior should follow Otter's runtime error rules.
Normal Control Flow Is Not Failure
Statements such as:
Output
return
must pass through try normally.
Example:
Otter
to findUser user
try
return user
otherwise
say "Could not find user."
.
.
If return user executes successfully, the function returns user.
The otherwise body must not run.
Normal control-flow changes are not runtime errors.
This rule should also apply to future control-flow features such as:
Output
break
continue