2.3.7 Try Except

A TRY-EXCEPT statement has the form:

    TRY
      Body
    EXCEPT
      id_1 (v_1) => Handler_1
    | ...
    | id_n (v_n) => Handler_n
    ELSE Handler_0
    END
where Body and each Handler are statements, each id names an exception, and each v_$i$ is an identifier. The ``ELSE Handler_0'' and each ``(v_$i$)'' are optional. It is a static error for an exception to be named more than once in the list of id's.

The statement executes Body. If the outcome is normal, the except clause is ignored. If Body raises any listed exception id_$i$, then Handler_$i$ is executed. If Body raises any other exception and ``ELSE Handler_0'' is present, then it is executed. In either case, the outcome of the TRY statement is the outcome of the selected handler. If Body raises an unlisted exception and ``ELSE Handler_0'' is absent, then the outcome of the TRY statement is the exception raised by Body.

Each (v_$i$) declares a variable whose type is the argument type of the exception id_$i$ and whose scope is Handler_$i$. When an exception id_$i$ paired with an argument x is handled, v_$i$ is initialized to x before Handler_$i$ is executed. It is a static error to include (v_$i$) if exception id_$i$ does not take an argument.

If (v_$i$) is absent, then id_$i$ can be a list of exceptions separated by commas, as shorthand for a list in which the rest of the handler is repeated for each exception. That is:

    id_1, ..., id_n => Handler
is shorthand for:
    id_1 => Handler | ... | id_n => Handler

It is a checked runtime error to raise an exception outside the dynamic scope of a handler for that exception. A ``TRY EXCEPT ELSE'' counts as a handler for all exceptions.

m3-support@elego.de