Previous Topic: Default Error ProcedureNext Topic: Categorizing Errors


Coding an Error Procedure

Errors are not always fatal. They can provide information about the error. In certain instances, the program can recover from the error and continue processing. To handle these situations, you can code an error procedure in the program.

You must name the coded error procedure ERROR. The DO statement can invoke it; however, it cannot be the object of a QUIT or PROCESS NEXT statement. The coded error procedure automatically executes when an error occurs. If the coded error procedure itself contains an error, the default error procedure executes. If a fatal error occurs, the coded procedure is ignored and the default error procedure executes.

A coded error procedure can take advantage of PDL statements to inform you of an error and maintain control. The NOTIFY statement can override the default termination message and provide a more informative message. The NOTIFY message displays with the next panel that is transmitted or at the termination of the run. Rather than terminate an entire run, the coded procedure can terminate just the current program.

For example, an error procedure can send an informative message to the screen and to the output file:

<<ERROR>> PROCEDURE
     LIST ERROR
     BACKOUT
     SET $RC = 12
     SET WOR‑NUM = $RC
     NOTIFY 'PROGRAM ABENDING - ' WOR‑NUM
     QUIT PROGRAM
 ENDPROC

You can create a panel to provide more detailed error information. The panel can include explanatory text, remedial information, and the $RC value.

When a user‑defined error procedure is invoked, you can set the value of the return code in that error procedure. The system does not reset the value.

At the end of the run, the value of $RC displays. This way, even a run that terminates normally can indicate an error during processing.