Instructions and Conditions

The instructions to set a trap for errors are SIGNAL and CALL. Example formats are:

SIGNAL ON condition NAME trapname
CALL ON condition NAME trapname

The SIGNAL ON instruction initiates an exit subroutine that ends the program. You use CALL ON to recover from a command error or failure. Both SIGNAL ON and CALL ON will cause a branch to the specified (or default) trapname whenever the condition occurs. With CALL ON you can RETURN to the clause following the one that raised the condition. With SIGNAL ON processing continues with the instructions following the trapname (maybe some cleanup or diagnostic code usually but not necessarily followed by EXIT).

The command conditions that can be trapped are:

ERROR Detects any nonzero error code the default environment issues as the result of a Rexx command.
FAILURE Detects a severe error, preventing the system from processing the command.

A failure, in this sense, is a particular category of error. If you use SIGNAL ON or CALL ON to set a trap only for ERROR conditions, then it traps failures as well as other errors. If you also specify a FAILURE condition, then the ERROR trap ignores failures.

With both the SIGNAL and the CALL instructions, you can specify the name of the trap routine. Add a NAME keyword followed by the name of the subroutine. If you do not specify the name of the trap routine, Rexx uses the value of condition as the name (Rexx looks for the label ERROR:, FAILURE:, and so on).

For more information about other conditions that can be trapped, see the Open Object Rexx: Reference.