TRY Expression

<try expression>

──┬─<try arithmetic expression>─┬──────────────────────────────────────┤
  ├─<try Boolean expression>────┤
  ├─<try complex expression>────┤
  └─<try pointer expression>────┘

Explanation

The TRY expression is similar to the TRY statement, except that the expression is used when a returned value is needed. The value returned by the TRY expression is the value returned by the expression or procedure call that finished normally.

Definitions of <try *kind* expression> can be found under Arithmetic Expressions, Boolean Expressions, Complex Expressions, and Pointer Expression.

When any kind of <try limited form> is used in the TRY expression, the types of error procedure and invoked procedure must match exactly. When <try limited form> is used in <try arithmetic expression>, the procedure identifier specified for the error procedure must be of type INTEGER, REAL, DINTEGER, or DOUBLE. Also, <procedure invocation statement> or <procedure reference statement> must invoke a procedure of type INTEGER, REAL, DINTEGER, or DOUBLE.

When any kind of <try *kind* normal form> is used in the TRY expression, the expressions must be of the same kind—for example, all arithmetic expressions or all Boolean expressions. For <try arithmetic normal form>, the type of a <try arithmetic expression> is DOUBLE if any of its constituent expressions are of type DOUBLE; in this case, a constituent expression that is not of type DINTEGER or DOUBLE is extended to double-precision. The type of a <try arithmetic expression> is INTEGER only if all its constituent expressions are of type INTEGER. Otherwise, a <try arithmetic expression> is of type REAL.

Examples of TRY Expressions

    R3 := TRY R1 * R2 ELSE 1;
        % If R1*R2 results in an overflow or any other fault,
        % then the real variable R3 is assigned 1.
    B1 := TRY (R1 * 100 >= R2) ELSE FALSE;
        % If the boolean expression (R1 * 100 >= R2) causes a fault,
        % then the boolean variable B1 is assigned FALSE.
    C2 := TRY C1 * C1 ELSE 1;
        % If the complex expression C1 * C1 causes a fault,
        % then the complex variable C2 is assigned 1.
    P1 := TRY (ARY[A1]) ELSE ARY[0];
        % If A1 is not within the valid range of the array ARY or
        % some other fault occurs during evaluation of ARY[A1],
        % then the pointer variable P1 is assigned ARY[0].