Conditions and Condition Traps
>>-+-CALL---+--+-OFF--condition--------------------+--;-------->< '-SIGNAL-' '-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.
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 in Action Taken
When a Condition Is Trapped.
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:
- As a term in an expression
- As the name following the VAR subkeyword of a PARSE instruction
- 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.
/* The following does not raise NOVALUE. */ signal on novalue a.=0 say a.z say 'NOVALUE is not raised.' exit novalue: say 'NOVALUE is raised.'
You can specify this condition only for SIGNAL ON.
- SYNTAX
- raised if any language processing error is detected while the program is running. This includes all kinds of processing errors, including true syntax errors and “run-time” errors, such as attempting an arithmetic operation on nonnumeric terms. You can specify this condition only for SIGNAL ON.
Any ON or OFF reference to a condition trap replaces the previous state (ON, OFF, or DELAY, and any trapname) of that condition trap. Thus, a CALL ON HALT replaces any current SIGNAL ON HALT (and a SIGNAL ON HALT replaces any current CALL ON HALT), a CALL ON or SIGNAL ON with a new trap name replaces any previous trap name, any OFF reference disables the trap for CALL or SIGNAL, and so on.
