The purpose of an interrupt declaration is to assign an identifier to the interrupt and specify the statements that are to be executed when the associated event is caused.
An interrupt cannot be passed any parameters. Otherwise, it has the same addressing environment as a procedure would have if it were declared at the same point in the program. That is, in ALGOL the interrupt can access objects declared within the interrupt and within any procedures that are declared globally to the interrupt.
In rare instances, you might want to restart the process at a point other than the point at which the process was interrupted. You can achieve this effect in ALGOL with a bad GO TO statement (that is, a GO TO statement that transfers control to a statement outside the interrupt). However, COBOL does not allow a GO TO statement to transfer control outside of the interrupt.
You should be aware of a side effect that arises from using a bad GO TO to exit an interrupt. During execution of an interrupt, the system automatically executes a general disable on all other interrupts used by the process. A bad GO TO out of an interrupt leaves the process with all interrupts disabled. You should include a general enable statement to correct this situation. (Refer to Using General Disable and Enable Statements later in this section.)
The following is an ALGOL example of an interrupt declaration:
INTERRUPT BLOCK1;
BEGIN
DISPLAY(“ERROR”);
DISPLAY(“INTERRUPT BLOCK1 OCCURRED”);
END;In COBOL, an interrupt declaration can occur only in the DECLARATIVES section of the procedure division. The following is an example of a DECLARATIVES section that includes an interrupt called INT-1:
DECLARATIVES.
INT SECTION.
USE AS INTERRUPT PROCEDURE.
INT-1.
DISPLAY “ERROR”.
DISPLAY “INTERRUPT 1 OCCURRED”.
END DECLARATIVES.
