ARexx maintains an internal interrupt system used to detect and trap certain error conditions. When an interrupt is enabled and its corresponding condition arises, a transfer of control to the label specific it that interrupt occurs. This allows a program to retain control in circumstances that might otherwise cause the program to terminate. The interrupt conditions can be caused by either synchronous events, like a syntax error, or asynchronous events, like a Ctrl+C break request.
These internal interrupts are completely separate from the hardware interrupt system managed by the EXEC operating system.
The name assigned to each interrupt is actually the label to which control will be transferred. Thus, a SYNTAX interrupt will transfer control to the label "SYNTAX:". Interrupts can be enabled or disabled using the SIGNAL instruction. For example, the instruction "SIGNAL ON SYNTAX" would enable the SYNTAX interrupt.
The interrupts supported by ARexx are:
This traps (detects and treats as a signal and not as normal output) a Ctrl+C break request generated by AmigaDOS. If the interrupt is not enabled, the program terminates immediately with the error message "Execution halted" and returns with the error code set to 2.
This traps a Ctrl+D break request issued by AmigaDOS. The break request is ignored if the interrupt is not enabled.
This traps a Ctrl+E break request issued by AmigaDOS. The break request is ignored if the interrupt is not enabled.
This traps a Ctrl+F break request issued by AmigaDOS. The break request is ignored if the interrupt is not enabled.
An external halt request is trapped if this interrupt is enabled. Otherwise, the program terminates immediately with the error message "Execution halted".
An interrupt occurs if an uninitialized variable is used while this condition is enabled. The usage could be within an expression, in the UPPER instruction, or with the VALUE() built-in function.
A syntax or execution error is generated by this interrupt. Not all such errors can be trapped. Certain errors occur before a program is executed and those detected by the ARexx external interface cannot be trapped by the SYNTAX interrupt.
When an interrupt forces a transfer of control, all of the currently active control ranges are dismantled and the interrupt that caused the transfer is disabled. This disabling prevents a possible recursive interrupt loop. Only the control structures in the current environment are affected, so an interrupt generated within a function will not affect the caller's environment.
Two special variables are affected when an interrupt occurs:
Always set to the current line number before the transfer of control takes place. This allows the determination of which source line is executed.
Set to the error code that caused the condition. For ERROR interrupts, this value will be a command return code and can usually be interpreted as an error severity level. The value for SYNTAX interrupts is always an ARexx error code.
Interrupts are useful for error-recovery actions. This involves informing external programs that an error occurred or reporting further diagnostics to isolate the problem. Program 15 issues a "message" command to an external host called "MyEdit" whenever a syntax error is detected.
/*A macro program for `MyEdit `*/
SIGNAL ON SYNTAX /*Enable interrupt*/
(normal processing)
EXIT
SYNTAX: /*Syntax error detected*/`
ADDRESS `MyEdit'
`message' `error' RC errortext (RC)
EXIT 10