Protection against All Conditions

You can use the unsafe form of the TRY statement to extend protection against all possible causes of termination.

Note: The unsafe form should be used with great care and only by programmers familiar with the operating system. In particular, it is important that unsafe TRY code execute quickly, so it does not monopolize system locks. It might also be necessary for the TRY code to cut back the process stack to prevent stack overflow errors. Misuse of the unsafe form can result in hung programs, system dumps, or halt/loads.

The unsafe form of the TRY statement is distinguished by the use of the PROTECTED clause, as follows:

TRY [:PROTECTED ] <statement> ELSE <statement>;

The PROTECTED clause of the TRY statement is only available in NEWP and DMALGOL, and in NEWP is only permitted in blocks marked with the UNSAFE block directive. The compiler marks the resulting object code file as nonexecutable. To enable execution of the object code file, an operator can use either of the following commands:

  • The MP <file title> + EXECUTABLE form of the MP (Mark Program) system command. This command removes the nonexecutable status so that the object code file can be initiated with the normal process initiation statements such as CALL, PROCESS, and RUN.

  • The SL <function name> = <file title> form of the SL (Support Library) system command. This command enables a nonexecutable object code file to be initiated by the library linkage mechanism when the library is linked to by function.

Note: An unsafe DMALGOL program is only nonexecutable if the security option DMALGOLUNSAFE is set.

The conditions protected against by the PROTECTED clause include:

  • Operator DS (Discontinue) commands applied to a normally executing process.

  • PARENT PROCESS TERMINATED conditions.

  • STATUS = VALUE(TERMINATED) assignments made by a different process.

  • Cancellation of a library linkage through 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. The unsafe TRY statement protects processes against this type of condition, even if the TRY statement is invoked after the library procedure call. For an example, refer to TRY Statements and Library Delinkage later in this section.

  • GO TO statements that attempt to exit outside the TRY statement.

Note: By default, the error-handling statement in the ELSE clause is not protected. To protect the error-handling statement, you could use multiple ELSE clauses as discussed under Providing Alternate Sets of Error Handling Code. Alternatively, you could protect the error-handling statement from interrupts with unsafe constructs such as the CONTROLSTATE block directive in NEWP or the DISALLOW statement in DMALGOL. You should use these unsafe constructs only to protect short code streams that do not include any procedure calls.