IB Statements/exit

From CometWiki

Jump to: navigation, search

EXIT statement

Syntax: EXIT [,EXCP=statement-label]

Discussion: The EXIT statement returns control to a calling program.

See the information about subprograms.

All subprograms invoked by an ENTER statement must ultimately terminate with an EXIT, EXITALL, or EXITTO statement to return control to the calling program. The EXIT statement returns control to the previous calling program. The EXITALL statement returns control to the top-level calling program (in the case of multi-level subprograms). The EXITTO statement returns control to a specified subprogram level.

A subprogram may execute overlay programs via the RUN statement, in which case the final overlay must execute an EXIT, EXITALL, or EXITTO statement to return to the calling program.

If an EXIT statement is executed without a prior ENTER statement having been executed, Comet returns an exception 66. By adding an exception path to the EXIT statement, program flow can be directed to a routine that tests for exception 66 and then RUNs the subsequent program overlay.

Example 1: Calling program

 ===========================
 .
 .
 .
 ENTER "SUBPROG",DIR="DSK"
 .
 .
 .
 .
 !
 Subprogram ("SUBPROG" on "DSK")
 ===============================
 .
 .
 .
 .
 .
 .
 .
 .
 EXIT
 

This example shows the relationship between a calling program and a subprogram. In this example, the calling program executes (via the ENTER statement) the subprogram named "SUBPROG" from the Comet directory named "DSK". The final statement in the subprogram (EXIT) returns control to the calling program at the statement immediately following the ENTER statement.

Example 2:

        EXIT, EXCP=LABEL1
       .
       .
       .
LABEL1: IF EXCP = 66 THEN RUN "PROGRAM"

This example shows how an exception path can be written for the EXIT statement. If an exception occurs when the EXIT statement is executed, the program will branch to LABEL1:, where the system variable EXCP is interrogated.

Personal tools