EXIT PROCEDURE

EXIT PROCEDURE

Declare an exit procedure

Syntax

       EXIT PROCEDURE <idProcedure>
              [FIELD <idField list> [IN <idAlias>]]
              [LOCAL <identifier> [[:= <initializer>]]]
              [MEMVAR <identifer list>]
              .
              . <executable statements>
              .
              [RETURN]

Arguments

EXIT PROCEDURE declares a procedure that will be executed on program termination.

<idProcedure> is the name of the exit procedure to declare. Exit procedure names can be any length, but only the first 10 characters are significant. Names may not begin with an underscore but can contain any combination of characters, numbers, or underscores.

FIELD declares a list of identifiers to use as field names whenever encountered. If the IN clause is specified, referring to the declared name includes an implicit reference to the specified alias.

LOCAL declares and optionally initializes a list of variables or arrays whose visibility and lifetime is the current procedure.

MEMVAR declares a list of identifiers to use as private or public memory variables or arrays whenever encountered.

RETURN passes control to the next exit procedure or to the operating system, if no other exit procedures are pending.

Description

The EXIT PROCEDURE statement declares a procedure that will be executed upon program termination. EXIT procedures are called after the last executable statement in application has completed. EXIT PROCEDUREs can be used to perform common housekeeping tasks such as saving configuration settings to a file, closing a log file, or concluding a communications session.

The visibility of exit procedures is restricted to the system; therefore, it is not possible to call an EXIT PROCEDURE from a procedure or user-defined function. Exit procedures do not receive parameters.

Once the last executable statement has completed, control passes from one EXIT PROCEDURE to the next until all procedures in the exit list have been called. Control then passes to the operating system.

The ANNOUNCE statement declares a module identifier for a source (.prg) file. Once declared, EXIT PROCEDUREs are referenced with this module identifier. An application may use any number of exit procedures by explicitly REQUESTing their module identifiers.

The EXIT PROCEDUREs requested for an application are collectively referred to as the exit list. There is no mandatory execution order of procedures in the exit list; however, if an EXIT PROCEDURE is declared in the same source (.prg) file as the application’s primary routine (root), it is guaranteed to be the first exit procedure called.

Termination of a given application can be attributed to any of the following:

       . RETURNing from the primary (root) routine 

       . the QUIT command 

       . issuing a BREAK without an enclosing BEGIN SEQUENCE...END 

       . unrecoverable error

    Execution of an EXIT PROCEDURE cannot be guaranteed when the system encounters an unrecoverable error. If         an error is raised during an exit procedure, the system returns to DOS. Pending exit procedures are not called.

Examples

       .  This example illustrates construction of a simple timing 
       mechanism using INIT and EXIT PROCEDUREs: 
       // prints the amount of time required to read, 
       // sort,  and display a list of file names. 
       ANNOUNCE MySystem 
       STATIC nStart 
       PROCEDURE Main()       AEVAL( ASORT( DIRECTORY( "*.*" ) ), ; 
               { | aFileInfo | QOUT( aFileInfo[ 1 ] ) } ) 
       RETURN 
       INIT PROCEDURE MyInit() 
          nStart := SECONDS() 
       RETURN 
       EXIT PROCEDURE MyExit() 
          ? 
          ? "Elapsed Time: " 
          ?? SECONDS() - nStart 
       RETURN

See Also

ANNOUNCE, REQUEST, INIT PROCEDURE

Advertisements

One response to “EXIT PROCEDURE

  1. Pingback: Harbour Statements | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s