IB Statements/errorsub

From CometWiki

Jump to: navigation, search

ERRORSUB statement

Syntax: ERRORSUB statement-label

(or)

ERRORSUB [SYSTEM]


Discussion: The ERRORSUB statement sets a default exception branch. The statement-label is the label of an exception routine that will be executed if a runtime exception occurs that is not handled by an exception path (i.e., by an EXCP= or EXCPSUB= exception trap).

ERRORSUB SYSTEM may be specified to clear the ERRORSUB statement currently in effect.

ERRORSUB is similar to the ERRORTO statement, but provides for easier program handling because, like a normal subroutine call, the next statement address is placed in the users's subroutine stack. When a RETURN is encountered after the ERRORSUB statement is executed, program execution continues at the statement immediately following the statement that produced the exception, and the return address is popped off the stack. Use of ERRORSUB lets program flow continue smoothly, without requiring the programmer to determine where the exception occurred and hence where the program should continue.

The statement-label is automatically cleared after execution, and unless it is reset by another ERRORSUB statement, subsequent un- trapped runtime exceptions will initiate the QENDITOR program.

Note: ERRORSUB and ERRORTO are mutually exclusive; only one can be active at a time. The latest one that is executed is the one in effect.

Example:

 ERRORSUB 9999
 .
 READ (1,1000)
 PRINT (2,2000)
 .
 9999 IF EXCP NE 33 THEN ERROR
    RETURN

In the above example, the default exception subroutine is established at statement 9999. If the READ statement encounters an exception, the program branches to 9999, where the system variable EXCP is interrogated. If EXCP is not equal to 33 (indicating "record extracted"), the program executes the ERROR termination procedure. Otherwise the program returns to the statement following the exception (in this case, the PRINT statement).

Personal tools