Does a Rexx SIGNAL ON trap stay armed after the handler runs?
0 reputation · 24 May 2022, 08:02 UTC
0 reputation · 24 May 2022, 08:02 UTC
Rexx condition trapping through SIGNAL ON diverts execution to a named routine when a condition such as ERROR, SYNTAX, NOVALUE, or NOTREADY is raised. A portable script that traps repeatedly, for example around failing commands in a retry loop, needs to know whether the condition stays enabled once the trap routine finishes, or whether SIGNAL ON must be re-issued before the next occurrence can be caught.
ANSI X3.274-1996 defines the trapping mechanism itself, but re-arm behavior after a handler runs is an area where interpreters may differ. Classic IBM Rexx and ooRexx are generally described as keeping a condition armed until an explicit SIGNAL OFF, while Regina may handle a SIGNAL ON issued inside an active handler, or nested traps, differently. Rexx also has no built-in idempotent-retry or exactly-once write construct, so this detail decides whether a second failure inside a loop is trapped at all.
Does a trapped condition stay armed after the handler routine completes, or must it be re-armed each time? How do classic IBM Rexx, ooRexx, and Regina differ on this point, especially for a SIGNAL ON issued from within an active handler?
In the three mainstream Rexx interpreters—classic IBM Rexx, ooRexx, and Regina—a SIGNAL ON trap remains active after its handler routine finishes. The trap is not cleared automatically; it will fire again on the next occurrence of the same condition until a SIGNAL OFF or a new SIGNAL ON for that condition is issued. The interpreter keeps the trap registration separate from the condition flag that is cleared when the condition is raised.
SIGNAL ON issued inside an active handler simply replaces the existing definition; the new definition will be used for future occurrences.SIGNAL ON as a redefinition rather than a nested trap, but the trap remains active until explicitly turned off.Because the trap stays armed, a retry loop can safely issue a single SIGNAL ON before the loop starts. Each failure inside the loop will invoke the handler without needing to re‑arm the trap on every iteration.
/* test.trap.rex */
SIGNAL ON ERROR HANDLER errorHandler
DO i = 1 TO 3
/* Force an ERROR condition */
ERROR "Iteration &i"
END
errorHandler:
SAY "Caught ERROR in handler, i = &i"
RETURN
rexx test.trap.rex
ooRexx test.trap.rex
regina test.trap.rex
SIGNAL ON.SIGNAL ON ERROR inside errorHandler that prints a different message. Verify that the outer trap remains active and the new definition takes effect for subsequent errors.REXXVER in IBM Rexx) to ensure it implements ANSI X3.274‑1996.Which Rexx interpreter and version are you using? Knowing the exact build can help confirm that the persistent trap behavior applies to your environment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.