• Reference Guide

try Statement

try block1
try block1 else block2
The try statement evaluates block1 and if its result is not an error (the Error type), the same result is returned by the entire try statement. If the result is an error, in the first case without the else-branch, the result is the initial value of the type of block1. In the case with the else-branch, block2 is then executed and its result is returned by the try statement. A special variable last_error is always defined in the block2, which contains the error occurred in the block1. It is possible either to analyze this error and correct it accordingly, or it can be encapsulated in a higher level error and returned by the try statement.
The expressions block1 and block2 are blocks in the sense that the scope of variables defined within them is limited to the block.
For details, se the chapter on error handling.