Example of Producing User-generated COBOL Run-Time System Errors
This example has been tested with Enterprise Developer 4.0 and with Visual COBOL 4.0 for Eclipse and Visual Studio.
In situations where an application fails with an error condition that it cannot recover from, you might want the application to terminate the process in such a way that error processing occurs. For such scenarios, Micro Focus provides the CBL_RUNTIME_ERROR library routine that enables you to display a custom message.
You need to call the CBL_RUNTIME_ERROR library routine from your code and provide a message string to indicate the error. The API that uses this routine takes a flags parameter. Setting the flag to 0 forces the application to terminate and generate the specified user COBOL Run-Time System error displayed as an RTS 150 message. The message enables the user to determine which (of potentially several) error condition caused the termination.
If the core_on_error tunable is also set, CBL_RUNTIME_ERROR makes it easier to debug application errors from a production environment.
CBL_RUNTIME_ERROR is a cross-platform library routine and can be used on both Windows and UNIX/Linux.
The following is an example of how to call this routine from your code:
01 ws-flags pic x(4) comp-5.
01 ws-error-str pic x(255).
display "This program will generate a COBOL Runtime"
" error to force termination."
move 0 to ws-flags
**** Null Terminated String for text is required.
move z"Application Generated Runtime Error" to ws-error-str
call "CBL_RUNTIME_ERROR" using by value ws-flags
by reference ws-error-str
display "This will never be reached as RTS Error handling is"
end program RTSERR1.
This code produces an error message at run time:
Execution error : file 'RTSERR1'
error code: 150, pc=0, call=1, seg=0
150 Program abandoned at user request (Application Generated Runtime Error)