You can code one or more ERROR declarative procedures that will be given control if an input or output error occurs during the execution of your program. If you do not code such procedures, your job could be canceled or abnormally terminated after an input or output error occurs.
Place each such procedure in the declaratives section of the PROCEDURE DIVISION. You can code:
In an ERROR declarative procedure, you can code corrective action, retry the operation, continue, or end execution. (If you continue processing a blocked file, though, you might lose the remaining records in a block after the record that caused the error.) You can use the ERROR declaratives procedure in combination with the file status key if you want a further analysis of the error.
Multithreading: Avoid deadlocks when coding I/O declaratives in multithreaded applications. When an I/O operation results in a transfer of control to an I/O declarative, the automatic serialization lock associated with the file is held during the execution of the statements within the declarative. If you code I/O operations within your declaratives, your logic might result in a deadlock as illustrated by the following sample:
Declaratives.
D1 section.
Use after standard error procedure on F1
Read F2.
. . .
D2 section.
Use after standard error procedure on F2
Read F1.
. . .
End declaratives.
. . .
Rewrite R1.
Rewrite R2.
When this program is running on two threads, the following sequence of events could occur:
related references
EXCEPTION/ERROR declarative (Enterprise COBOL Language Reference)