Chapter 17. Conditions and Condition Traps
A condition is a specified event or state that CALL ON or SIGNAL ON can trap. A condition trap can
modify the flow of execution in a REXX program. Condition traps are turned on or off using the ON or OFF
subkeywords of the SIGNAL and CALL instructions (see section “CALL” on page 135 and section
“SIGNAL” on page 164).
CALL
SIGNAL
OFF condition
ON condition
NAME trapname
;
condition and trapname are single symbols that are taken as constants. Following one of these
instructions, a condition trap is set to either ON (enabled) or OFF (disabled). The initial setting for all
condition traps is OFF.
If a condition trap is enabled and the specified condition occurs, control passes to the routine or label
trapname if you have specified trapname. Otherwise, control passes to the routine or label condition. CALL
or SIGNAL is used, depending on whether the most recent trap for the condition was set using CALL ON
or SIGNAL ON, respectively.
Note: If you use CALL, the trapname can be an internal label, a built-in function, or an external routine. If
you use SIGNAL, the trapname can be only an internal label.
The conditions and their corresponding events that can be trapped are:
ERROR
raised if a command indicates an error condition upon return. It is also raised if any command
indicates failure and neither CALL ON FAILURE nor SIGNAL ON FAILURE is active. The condition is
raised at the end of the clause that called the command but is ignored if the ERROR condition trap is
already in the delayed state. The delayed state is the state of a condition trap when the condition has
been raised but the trap has not yet been reset to the enabled (ON) or disabled (OFF) state. See note
3 on page 227.
CALL ON ERROR and SIGNAL ON ERROR trap all positive return codes, and negative return codes
only if CALL ON FAILURE and SIGNAL ON FAILURE are not set.
FAILURE
raised if a command indicates a failure condition upon return. The condition is raised at the end of the
clause that called the command but is ignored if the FAILURE condition trap is already in the delayed
state.
CALL ON FAILURE and SIGNAL ON FAILURE trap all negative return codes from commands.
HALT
raised if an external attempt is made to interrupt and end execution of the program. The condition is
usually raised at the end of the clause that was being processed when the external interruption
occurred.
NOVALUE
raised if an uninitialized variable is used:
v As a term in an expression
v As the name following the VAR subkeyword of a PARSE instruction
v As a variable reference in a parsing template, a PROCEDURE instruction, or a DROP instruction.
Note: SIGNAL ON NOVALUE can trap any uninitialized variables except tails in compound
variables.
© Copyright IBM Corp. 1992, 2009 225