Unlike some mainframe languages (eg. COBOL) PL/1 supports the concept of programmer defined interrupts that will be executed when some predefined condition occurs. These conditions may be either system or programmer defined.
These interrupts can be used to execute different code depending on where in the program that the condition occurs because the interrupt applies from the time that it is declared through to the completion of the current procedure (or the declaration of the same interrupt again later within the same procedure). The interrupt will also be applied if the condition occurs in any procedures called within the current procedure and any procedures that they call unless the same interrupt is defined at that lower level.
What does this means? Let's assume that if we have a main procedure that calls procedures A, B, and C. Now let's also assume that each of these lower level procedures all call procedure X and that we define a particular interrupt in the main procedure and in procedure B. Now if the condition occurs in procedure X then the interrupt processing to be performed will be that specified in procedure B if procedure X was called from procedure B. If procedure X was called from procedure A or procedure C then the interrupt processing defined in the main procedure will be applied.
By using interrupts, we can define different processing to be performed when a particular condition occurs depending on the program path followed to reach that point without having to keep track of the path ourselves.
The default system interrupt is ON ERROR which is used to specify the code that is to execute whenever a system error occurs that does not have its own interrupt specifically defined.
Other system interrupts include ON ZERODIVIDE (which can be abbreviated to ON ZDIV), ON ENDFILE, ON FIXEDOVERFLOW (which can be abbreviated to ON FOFL), ON CONVERSION (which can be abbreviated to ON CONV), ON RECORD, ON SIZE, ON SUBSCRIPTRANGE (which can be abbreviated to ON SUBRG), and ON STRINGRANGE (which can be abbreviated to ON STRG).
During testing of your program, you can simulate these conditions to test the interrupt by specifying a SIGNAL condition statement in the code where you want the simulated system condition to occur. All you need do is to specify the appropriate condition name for the interrupt that you want to trigger.
The SIGNAL statement has a second use and that is in defining when your own interrupts are to be executed. You can define any additional interrupts that you like by creating ON condition statements where the specified condition name is anything except one of the values used by the system conditions. This interrupt will not be triggered by having any system condition occur as its name doesn't match any of the system conditions that can be raised but it will be triggered whenever a SIGNAL statement specifying that condition name is executed.
This article written by Stephen Chapman, Felgall Pty Ltd.