try

The EGL try statement marks the beginning of a try block, which ends with the end delimiter. The try statement keeps a program running even one of the following statements within the try block results in an error:

The try statement gives you the ability to dictate the results of any exceptions your code might encounter, from minor ones such as end of file or record not found, to more serious problems such as hard I/O errors. If an exception occurs, processing resumes at the first statement in an onException block that matches the exception type. Though there is no obvious reason for doing so, you can omit the onException block, in which case execution resumes at the first statement following the end of the try block.

A typical try block contains two groups of statements:

Exceptions propagate upward from the point of the error. A try statement can handle an exception that occurs within any functions called from the try block, no matter how deeply nested. The nearest enclosing try block gets control after an exception is thrown. If no matching exception is found in an onException block, the next highest enclosing try block receives control. If no further try blocks are found, the next executable statement receives control.

For more information on the exception handling process, see Exception handling.

Syntax

Syntax diagram for the try statement
statement
Any EGL statement.
exceptionRecordVariable
A declaration of a record with the Exception stereotype (see "The Exception stereotype"). This record variable holds the messageID and message, as well as possible additional fields, for the exception if the record type matches that of the exception.

Compatibility

Table 1. Compatibility considerations for try statement
Platform Issue
DL/I database access If either dliVar.handleHardDLIErrors or vgVar.handlHardIOErrors is set to 1, the program continues running when a hard I/O error occurs within a try block for a DL/I segment. If both system variables are set to 0 or there is no try block, the program ends on an hard I/O error for a DL/I segment. dliVar.handleHardDLIErrors has no effect on serial records associated with IMS™ message queues or GSAM files.
V60 exception compatibility
  • You can have only a single onException block within a try block, and you cannot specify an exception type.
  • You can use the sysLib.currentException variable to determine the nature of the problem. This variable is only available in V6 compatibility mode.
  • Exceptions do not propagate beyond the part in which they occur. If an error occurs within a function called by a try block, the try block never sees the exception.
  • Hard I/O errors terminate the application unless you set the handleHardIOErrors program property to YES. In that case, EGL throws an exception so the program can handle the hard I/O error itself.
VisualAge® Generator compatibility mode If vgVar.handlHardIOErrors is set to 1, the program continues running when a hard I/O error occurs within a try block for database or file I/O. If vgVar.handlHardIOErrors is set to 0 or there is no try block, the program ends on an hard I/O error for database or file I/O. The default for vgVar.handleHardIOErrors is 1, but you can set the handleHardIOErrors program property to NO to provide a default setting of 0, which was the default in VisualAge Generator.

Feedback