Writing routines for handling errors

You can handle most error conditions that might occur while your program is running by using the ON EXCEPTION phrase, ON SIZE ERROR phrase, or other language constructs. But if an extraordinary condition such as a machine check occurs, usually your application is abnormally terminated.

Enterprise COBOL and Language Environment® provide a way for a user-written program to gain control when such conditions occur. Using Language Environment condition handling, you can write your own error-handling routines in COBOL. They can report, analyze, or even fix up a program and enable it to resume running.

Start of changeMost messages from the COBOL runtime are produced by signaling the corresponding condition. This means that your error handler will get control. For I (Information) and W (Warning) level conditions, you can simply percolate the condition, and the runtime will take care of displaying the message and resuming the execution. In particular, this is required for various compiler generated runtime diagnostics with a MSG option (for example, SSRANGE(,MSG)) to work as intended.End of change

When you write your own error-handling routines for an application, the COBOL programs must be compiled with appropriate compiler options. For more information, see OPTIMIZE.

To have Language Environment pass control to a user-written error program, you must first identify and register its entry point to Language Environment. PROCEDURE-POINTER data items enable you to pass the entry address of procedure entry points to Language Environment services.

Related references  
OPTIMIZE