Handling Exceptions

This chapter explains how ILE RPG exception handling works, and how to use:
  • Exception handlers
  • ILE RPG-specific handlers
  • ILE condition handlers
  • Cancel handlers
ILE RPG supports the following types of exception handlers:
  • RPG-specific handlers, for example, the use of an error indicator, an 'E' operation code extender, a MONITOR group, or a *PSSR or INFSR error subroutine.
  • ILE condition handlers, user-written exception handlers that you register at run time using the ILE condition handler bindable API CEEHDLR.
  • ILE cancel handler which can be used when a procedure ends abnormally.

Most programs benefit from some sort of planned exception handling because it can minimize the number of unnecessary abnormal ends (namely, those associated with function checks). ILE condition handlers also allow you to handle exceptions in mixed-language applications in a consistent manner.

You can use the RPG exception handlers to handle most situations that might arise in a RPG application. The minimum level of exception handling which RPG provides is the use of error indicators on certain operations. To learn how to use them, read the following sections in this chapter:
Additionally, to learn how ILE exception handling works, read:
For information on exception handling and the RPG cycle, see IBM® Rational® Development Studio for i: ILE RPG Reference.
Note: In this book the term 'exception handling' is used to refer to both exception handling and error handling. However, for consistency with other RPG terms, the term 'error' is used in the context of 'error indicator' and 'error subroutine'.