COPY QUSEC OF QSYSINC-QCBLLESRC.
ᑍ
ᑍ Miscellaneous elements
ᑍ
1 MISC.
5 Y PIC S9(9) VALUE .
1 ERROR-HANDLER PROCEDURE-POINTER.
1 OLD-ERROR-HANDLER PROCEDURE-POINTER.
1 NUMERIC-GROUP.
5 X PIC 9(3).
ᑍ
ᑍ Beginning of mainline
ᑍ
PROCEDURE DIVISION.
MAIN-LINE.
ᑍ
ᑍ Register the COBOL Error Handler.
ᑍ
ᑍ Initialize the error code parameter. To signal exceptions to
ᑍ this program by the API, you need to set the bytes provided
ᑍ field of the error code to zero. Because this program has
ᑍ exceptions sent back through the error code parameter, it sets
ᑍ the bytes provided field to the number of bytes it gives the
ᑍ API for the parameter.
ᑍ
MOVE 16 TO BYTES-PROVIDED.
ᑍ
ᑍ Set ERROR-HANDLER procedure pointer to entry point of
ᑍ ERRHDL1 ᑍPGM
ᑍ
SET ERROR-HANDLER TO ENTRY LINKAGE PROGRAM "ERRHDL2".
ᑍ
ᑍ
ᑍ Call the API to register the exit point.
ᑍ
CALL "QlnSetCobolErrorHandler" USING ERROR-HANDLER,
OLD-ERROR-HANDLER,
QUS-EC.
ᑍ
ᑍ If an exception occurs, the API returns the exception in the
ᑍ error code parameter. The bytes available field is set to
ᑍ zero if no exception occurs and greater than zero if an
ᑍ exception does occur.
ᑍ
IF BYTES-AVAILABLE >
DISPLAY "Error setting handler",
STOP RUN.
ᑍ
ᑍ If the call to register an error handler is successful, then
ᑍ cause a the data decimal error (X is initialized to blanks).
ᑍ
ADD X TO Y.
ᑍ
ᑍ Should not get here due to data decimal error
ᑍ
STOP RUN.
ᑍ
ᑍ End of MAINLINE
Appendix B. Original Examples in Additional Languages B-123