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.
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.
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 |
|
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. |