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