ILE COBOL Error and Exception Handling

ILE COBOL contains special elements to help you anticipate and correct error conditions that can occur when your program is running. Even if your code is flawless, errors may occur in the system facilities that your program uses.

You can anticipate possible error conditions by putting code into your program to handle them. If error-handling code is not present in your program, your program could behave in a manner that you did not anticipate, data files could be corrupted, and incorrect output may be produced. Without error-handling code, you may not even be aware that a problem exists.

The action taken by your error-handling code can vary from attempting to cope with the situation and continue, to issuing a message, to halting the program. At a minimum, coding an error message to identify an error condition is a good idea.

When you run an ILE COBOL program, several types of errors can occur. The ILE COBOL statement active at the time of a given error causes certain ILE COBOL clauses or phrases to be run.

This chapter discusses how to:
  • Use error-handling bindable APIs
  • Initiate deliberate dumps
  • Handle errors in string operations
  • Handle errors in arithmetic operations
  • Handle errors in input-output operations
  • Handle errors in sort/merge operations
  • Handle exceptions on the CALL statement
  • Create user-written error-handling routines.