Protection against Most Conditions

The basic form of the TRY statement is

TRY <statement> ELSE <statement>;

TRY executes the first statement or expression. If an error occurs during execution, TRY then executes the statement or expression in the ELSE clause. Control then continues to the next statement after the TRY statement.

This form of the TRY statement protects processes against most termination conditions, including the following:

  • Faults detected by the hardware, such as divide-by-zero conditions. (These faults could also be trapped by an ON statement in ALGOL or NEWP.)

  • Untrapped I/O errors.

  • Security errors. However, the system ignores the TRY error-handling code and terminates the process if the SAVEVIOLCOUNT usercode attribute is set and the error causes the VIOLATIONCOUNT usercode attribute to exceed the value of the VIOLATIONLIMIT usercode attribute.

  • Task attribute errors.

  • Library linkage errors caused by an attempt to invoke an imported procedure that is not available for one of the following reasons:

    • The procedure is not supplied by the linked library.

    • The procedure is in a library that could not be linked.

    • The procedure is in an unlinked library with AUTOLINK set to FALSE.

  • Delinkage of a library by a DELINKLIBRARY statement with the ABORT option. Normally, the ABORT option causes the system to discontinue any processes that are executing a procedure imported from the linked library. To protect processes against this condition, the TRY statement must be invoked before the library procedure call. For example, refer to TRY Statements and Library Delinkage later in this section.

  • Operator DS (Discontinue) commands applied to a process waiting on an RSVP, ACCEPT, or unit clear action. (An operator can still discontinue the process by entering a second DS command.)

  • Assignments of MYSELF.STATUS to VALUE(TERMINATED).

The TRY statement does not handle exception conditions that would not result in process termination. Such conditions include bad GO TO statements and exponent underflow faults. Such conditions can be trapped by an ON statement or EXCEPTION procedure, however.