4.2.2 How to Set up a Condition Trap How do you set the information in a condition trap? You do it with a SIGNAL or CALL clause, with the ON or OFF subkeyword. Remember that a condition trap contain three pieces of information? Here are the rules for how to set them: · To set the trap method, use either SIGNAL or CALL as keyword. · To set state to ON or OFF, use the appropriate subkeyword in the clause. Note that there is no clause or function in REXX, capable of setting the state of a trap to DELAY. · To set the condition handler, append the term “NAME handler” to the command. Note that this term is only legal if you are setting the state to ON; you can not specify a handler when setting the state to OFF. The trap is said to be “enabled” when the state is either ON or DELAY, and “disabled” when the state is OFF. Note that neither the event queue, nor the current trapped condition can be set explicitly by REXX clauses. They can only be set as a result of incidents, when raising and trapping conditions. It sounds very theoretical, doesn’t it? Look at the following examples, which sets the trap MYTH: /* 1 */ SIGNAL ON MYTH NAME TRAP_IT /* 2 */ SIGNAL OFF MYTH /* 3 */ CALL ON MYTH NAME MYTH_TRAP /* 4 */ CALL ON MYTH /* 5 */ CALL OFF MYTH Line 1 sets state to ON, method to SIGNAL and handler to TRAP_IT. Line 2 sets state to OFF, handler and method becomes undefined. Line 3 sets state to ON, method to CALL, and handler to MYTH_TRAP. Line 4 sets state to ON, method to CALL and handler to MYTH (the default). Line 5 sets state to OFF, handler and method become undefined. Why should method and handler become undefined when the trap in state OFF? For two reasons: firstly, these values are not used when the trap is in state OFF; and secondly, when you set the trap to state ON, they are redefined. So it really does not matter what they are in state OFF. What happens to this information when you call a subroutine? All information about traps are inherited by the subroutine, provided that it is an internal routine. External routines do not inherit any information about traps, but use the default values. Note that the inheritance is done by copying, so any changes done in the subroutine (internal or external), will only have effect until the routine returns.
PREV NEXT