When a program dynamically calls a separately compiled program, the called program might be unavailable. For example, the system might be out of storage or unable to locate the load module. If the CALL statement does not have an ON EXCEPTION or ON OVERFLOW phrase, your application might abend.
Use the ON EXCEPTION phrase to perform a series of statements and to perform your own error handling. For example, in the code fragment below, if program REPORTA is unavailable, control passes to the ON EXCEPTION phrase.
MOVE “REPORTA” TO REPORT-PROG
CALL REPORT-PROG
ON EXCEPTION
DISPLAY “Program REPORTA not available, using REPORTB.'
MOVE ”REPORTB“ TO REPORT-PROG
CALL REPORT-PROG
END-CALL
END-CALL
The ON EXCEPTION phrase applies only to the availability of the called program. If an error occurs while the called program is running, the ON EXCEPTION phrase is not performed.