EGL Reference Guide for iSeries

try blocks

An EGL try block is a series of zero to many EGL statements within the delimiters try and end. An example is as follows:

  if (userRequest = "A")
    try
      add record1;
    onException
      myErrorHandler(12);
    end
  end

In general, a try block allows your program to continue processing even if an error occurs.

The try block may include an onException clause, as shown earlier. That clause is invoked if one of the earlier statements in the try block fails; but in the absence of an onException clause, an error in a try block causes invocation of the first statement that immediately follows the try block.

The previous details on try blocks must be qualified. First, a try block affects processing only for errors in the following kinds of EGL statements:

Processing of numeric overflows is not affected by the presence of a try block. For details on those kinds of error, see sysVar.handleOverflow.

Second, a try block has no effect on errors inside a user function (or program) that is invoked from within the try block. In the next example, if a statement fails in function myABC, the program ends immediately with an error message unless function myABC itself handles the error:

  if (userRequest = "B")
    try
      myVariable = myABC();
    onException
      myErrorHandler(12);
    end
  end

Third, the program ends immediately and with an error message in the following cases:

The following cases are also of interest:

Note:
To support the migration of programs written in VisualAge Generator and EGL 5.0, the variable sysVar.handleSysLibErrors (previously called ezereply) allows you to process some errors that occur outside of a try block. Avoid use of that variable, which is available only if you are working in VisualAge Generator compatibility mode.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]