Chapter 10. Errors and Condition Trapping

Overview

Full-featured programming languages require a mechanism through which programmers can catch, or trap, exceptions or errors. In Rexx, this is often referred to as exception handling or condition trapping.

Rexx offers a simple, but serviceable means for trapping exceptional conditions. When an exception occurs, control is transferred to a routine to address the error. After the error routine handles the condition, execution of the primary script can resume.

This chapter explores Rexx's exception-trapping mechanism and the way in which you can use it in scripts to identify, capture, and manage errors. First, we'll discuss the specific kinds of errors that Rexx can trap. We'll discuss how to set up, or enable, error trapping. Then we'll take a look at a program that illustrates the exception-trapping mechanism. We'll progressively improve this program to expand its error-trapping capabilities and demonstrate different approaches to managing errors. We conclude by mentioning some of the limitations of exception conditions in standard Rexx, and how some Rexx interpreters extend beyond the ANSI standards to provide more generalized error trapping.

Error Trapping

When an error condition occurs, it is considered to be raised. Rexx interpreters that adhere to the TRL-2 standard allow the raising of six different error conditions, while the ANSI-1996 standard adds a seventh error condition. The table below lists all the error conditions:

Error Condition ...

Get Rexx Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.