Using the HANDLE CONDITION ERROR command

The following example shows you how to trap unexpected errors with the HANDLE CONDITION ERROR command.

About this task

Figure 1 shows the first of only two HANDLE CONDITION commands used in program ACCT01:
Figure 1. Trapping the unexpected with the HANDLE CONDITION ERROR command
 PROCEDURE DIVISION.
*
* INITIALIZE.
* TRAP ANY UNEXPECTED ERRORS.
EXEC CICS HANDLE CONDITION
ERROR(OTHER-ERRORS)
END-EXEC.
*

The HANDLE CONDITION ERROR command passes control to the paragraph at label OTHER-ERRORS if any condition arises for a command that does not specify NOHANDLE or RESP.

This command is the first command executed in the procedure division of this COBOL program. This is because a HANDLE CONDITION command must be processed before any CICS® command is processed that can raise the condition being handled. However, your program does not see the effects when it processes the HANDLE CONDITION command; it only sees them later, if and when it issues a CICS command that raises one of the named conditions.

In this, and the other ACCT programs, you generally use the RESP option. All the commands that specify the RESP option are written with a "catch-all" test ( IF RESPONSE NOT = DFHRESP(NORMAL) GO TO OTHER-ERRORS ) after any explicit tests for specific conditions. Therefore, other than the exceptions that you specifically anticipate, any exceptions take control to the paragraph at OTHER-ERRORS in each program. Those relatively few commands that do not have RESP on them take control to the same place if they result in any condition other than NORMAL because of this HANDLE CONDITION ERROR command.



dfhp3_exc_handlecondition_error.html | Timestamp icon Last updated: Monday, 5 June 2017