CL Error-Handling With APIs
May 2, 2012 Ted Holt
Note: The code accompanying this article is available for download here.
I had the great pleasure of meeting Brian Rusch in Milwaukee last month, when I spoke to the Wisconsin Midrange Computer Professionals Association (WMCPA). Brian told me about the method his shop uses to handle CL program exceptions. I’d like to share it with you.
IBM has established an architecture for exception handling. When a program exception occurs, the system may send one or more diagnostic messages that give information about the error. The system does send an escape message, which summarizes the problem and cancels the program.
Brian’s method takes advantage of this architecture. Brian has written command interfaces to two IBM-supplied APIs: Move Program Messages (QMHMOVPM); and Resend Escape Message (QMHRSNEM). His command MOVPGMMSG runs QMHMOVPM in order to forward the diagnostic messages to the caller. Brian’s RSNESCMSG command uses API QMHRSNEM to resend the escape message to the caller and cancel the failing program. His exception handling is easily handled with the following code:
MONMSG CPF0000 EXEC(GOTO ABEND) . . . more code . . . RETURN ABEND: MOVPGMMSG MSGTYPE(*DIAG) RSNESCMSG
In 2004, I published a template with roots in the System/38. If you compare this code to the code I published eight years ago, you’ll see that Brian’s code is much shorter and simpler than mine. There are no loops, and five of the variables in my code are not needed in his.
My hat is off to Brian Rusch for making simple interfaces for two messy APIs. The downloadable source code files contain not only Brian’s command source, but two example programs you can play with. One uses his commands. The other uses a slightly modified version of the template I use in my shop.