14. Signal Where other programming languages have the "goto" command, Rexx has "signal". The instruction "signal label" makes the program jump to the specified label (which is a name followed by a colon, the same as is used to start an internal subroutine or function). However, once this has been done, it is not possible to resume any "select" or "do" control structures that have recently been entered. Thus the main use of "signal" is to jump to an error handling routine when something goes wrong, so that the program can clean up and exit. There is a much more useful way of using "signal", however. That is to trap certain kinds of error condition. The conditions which may be trapped include: "syntax" (that is, any syntax error), "error" (any environment command that results in a non-zero exit code), "halt" (when the user interrrupts execution) and "novalue" (which is when a symbol is used without having been given a value). Error trapping for one of these conditions is turned on by signal on and is turned off by signal off When one of these conditions occurs, the program immediately signals to a label whose name is the same as that of the condition. Trapping is turned off, so another "signal on" will be required if you want to continue to trap that condition. If you wish for the program to signal to a label whose name is not the same as that of the condition, then you may specify that label using the "name" parameter of a "signal on" instruction, like this: signal on syntax name my_label Whenever a "signal" occurs, the variable "sigl" is set to the line number of the instruction which caused the jump. If the signal was due to an error trap, then the variable "rc" will be set to an error code. /* This program goes on forever until someone stops it. */ I say "Press Control-C to halt" O say "Press Control-C or Control-Break to halt" signal on halt do i=1 say i do 10000 end end halt: say "Ouch!" say "Died at line" sigl