Hello Loic,
I tried the example in the link and it worked fine for me. There were some formatting errors causing compile time errors which I had to fix myself though - sorry about that. Regardless, I found the example can be improved and will work with Debbie (IBM) to get that done later. In the meantime, I came up with a simple version below that would give you the idea about how try/catch works and help you test and debug the functionality in your environment. Could you try it and let me know how it goes?
(Note that I also attached 'error_recovery_le.txt' (plain text) that contains the same contents below for your convenience)
------------------------------------------------------------
1. An example of CEEMRCE called by COBOL:
PGM1 registers a condition handler (UCH1) using CEEHDLR and sets a resume point using CEE3SRP. When a condition occurs (in this example, ANSWER = 1 / 0), UCH1 gets a control to handle the condition and resumes the program execution to the resume point in PGM1.
To try the following example, compile PGM1 and UCH1, and statically linked them together to generate a program object (load module) named PGM1. Then run PGM1.
Module/File Name: PGM1
CBL NODYNAM
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM1.
*Module/File Name: PGM1
*------------------------------------------*
* Sample program using CEE3SRP and CEEMRCE.*
* PGM1 registers user-written condition *
* handler UCH1 using CEEHDLR. It *
* sets a resume point using CEE3SRP. *
*------------------------------------------*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECOVERY-AREA EXTERNAL.
05 RECOVERY-POINT POINTER.
05 ERROR-INDICATOR PIC X(01).
01 UCH-ROUTINE PROCEDURE-POINTER.
01 FIELDS.
05 FIRST-TIME-SW PIC X(03) VALUE ' ON'.
88 FIRST-TIME-88 VALUE ' ON'.
05 ANSWER PIC S9(01) COMP-3 VALUE 0.
05 TOKEN PIC S9(09) BINARY.
05 FC.
10 CASE-1.
15 SEVERITY PIC S9(04) BINARY.
15 MSG-NO PIC S9(04) BINARY.
10 SEV-CTL PIC X(01).
10 FACILITY-ID PIC X(03).
10 I-S-INFO PIC S9(09) BINARY.
PROCEDURE DIVISION.
DISPLAY "PGM1: === BEGINS ==="
SET UCH-ROUTINE TO ENTRY 'UCH1'.
*------------------------------------------*
* Register the condition handler, UCH1. *
*------------------------------------------*
CALL 'CEEHDLR' USING UCH-ROUTINE, TOKEN, FC.
IF CASE-1 NOT = LOW-VALUE
DISPLAY "PGM1: ERROR: CALL CEEHDLR FAILED"
GOBACK.
DISPLAY "PGM1: === CALL COMPUTE-LOOP 2 TIMES ==="
DISPLAY " "
PERFORM COMPUTE-LOOP 2 TIMES.
SET RECOVERY-POINT TO NULL.
DISPLAY "PGM1: === ENDS ==="
GOBACK.
COMPUTE-LOOP.
DISPLAY "PGM1: COMPUTE-LOOP BEGINS"
IF FIRST-TIME-88
MOVE 'OFF' TO FIRST-TIME-SW
*------------------------------------------*
* Set up a resume point. *
*------------------------------------------*
CALL 'CEE3SRP' USING RECOVERY-POINT, CASE-1
SERVICE LABEL
IF CASE-1 NOT = LOW-VALUE
DISPLAY "PGM1: ERROR: CALL CEE3SRP FAILED"
GOBACK
END-IF
display "PGM1: RESUME POINT"
END-IF
IF ERROR-INDICATOR = 'E'
MOVE SPACE TO ERROR-INDICATOR
MOVE 1 TO ANSWER
END-IF
* Application code may go here.
DISPLAY "PGM1: BEFORE DOING 1 / " ANSWER.
COMPUTE ANSWER = 1 / ANSWER.
DISPLAY "PGM1: AFTER DOING 1 / " ANSWER.
DISPLAY "PGM1: COMPUTE-LOOP ENDS"
DISPLAY " "
EXIT.
END PROGRAM PGM1.
Module/File Name: UCH1
CBL NODYNAM APOST
IDENTIFICATION DIVISION.
PROGRAM-ID. UCH1.
*Module/File Name: UCH1
*------------------------------------------*
* Sample user condition handler using *
* CEEMRCE. This program sets an error *
* flag for the program-in-error to query *
* and issues a call to CEEMRCE to return *
* control to the statement following the *
* call to CEE3SRP. *
*------------------------------------------*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECOVERY-AREA EXTERNAL.
05 RECOVERY-POINT POINTER.
05 ERROR-INDICATOR PIC X(01).
01 FC.
10 CASE-1.
15 SEVERITY PIC S9(04) BINARY.
15 MSG-NO PIC S9(04) BINARY.
10 SEV-CTL PIC X(01).
10 FACILITY-ID PIC X(03).
10 I-S-INFO PIC S9(09) BINARY.
LINKAGE SECTION.
01 CURRENT-CONDITION PIC X(12).
01 TOKEN PIC X(04).
01 RESULT-CODE PIC S9(09) BINARY.
88 RESUME VALUE +10.
88 PERCOLATE VALUE +20.
88 PERC-SF VALUE +21.
88 PROMOTE VALUE +30.
88 PROMOTE-SF VALUE +31.
01 NEW-CONDITION PIC X(12).
PROCEDURE DIVISION USING CURRENT-CONDITION,
TOKEN,
RESULT-CODE,
NEW-CONDITION.
DISPLAY " > UCH1: RECOVERY BEGINS"
DISPLAY " > UCH1: MOVE E TO ERROR-INDICATOR"
MOVE 'E' TO ERROR-INDICATOR.
*------------------------------------------*
* Call CEEMRCE to return control to the *
* last resume point. *
*------------------------------------------*
CALL 'CEEMRCE' USING RECOVERY-POINT, FC.
IF CASE-1 NOT = LOW-VALUE
DISPLAY " > UCH1: ERROR: CALL CEEMRCE FAILED"
GOBACK.
MOVE +10 TO RESULT-CODE.
DISPLAY " > UCH1: GO BACK TO RESUME POINT"
GOBACK.
END PROGRAM UCH1.
PGM1: === BEGINS ===
PGM1: === CALL COMPUTE-LOOP 2 TIMES ===
PGM1: COMPUTE-LOOP BEGINS
PGM1: RESUME POINT
PGM1: BEFORE DOING 1 / 0
> UCH1: RECOVERY BEGINS
> UCH1: MOVE E TO ERROR-INDICATOR
> UCH1: GO BACK TO RESUME POINT
PGM1: RESUME POINT
PGM1: BEFORE DOING 1 / 1
PGM1: AFTER DOING 1 / 1
PGM1: COMPUTE-LOOP ENDS
PGM1: COMPUTE-LOOP BEGINS
PGM1: BEFORE DOING 1 / 1
PGM1: AFTER DOING 1 / 1
PGM1: COMPUTE-LOOP ENDS
PGM1: === ENDS ===
------------------------------
Roy Bae
------------------------------
Original Message:
Sent: Thu March 07, 2024 10:44 AM
From: Loic Vital-Durand
Subject: Try/Catch in COBOL
Hello,
I tried the COBOL example of 'try/catch' I copied from this page : CEEMRCE-Move resume cursor explicit - IBM Documentation but it doesn't work.
I compiled the 3 programs and submited pgm2 using a JCL.
pgm2 abended here : COMPUTE ANSWER = 1 / ANSWER. with S0CB (Decimal-Divide Exception) and the handler UCH1 was not used.
I guess I did something wrong but no idea what.
Any suggestion welcome.
/Loic
------------------------------
Loic Vital-Durand
------------------------------