Previous Topic: EJECT StatementNext Topic: Notes for SQL Access


Error Procedure

The error procedure specifies a set of actions to invoke whenever an execution‑time error occurs. The error procedure also enables the program to provide for cases when certain conditions occur that could be handled and allow the program run to continue to completion.

For example, the error procedure can process an invalid numeric value condition and then return control to the processing procedure:

<<ERROR>> PROC
     IF $ERROR‑CLASS = 'NUM'
        LIST ERROR
         PROCESS NEXT GET‑NEXT‑LOOP
     ELSE
        LIST ERROR
        BACKOUT
        QUIT RUN
     ENDIF
ENDPROC

Coding an error procedure is optional. It lets you process abnormal errors explicitly by overriding the default error procedure. The default error procedure does the following:

  1. Issues a LIST ERROR statement that varies depending on the type of error.
  2. Performs a BACKOUT.
  3. Issues a standard message.
  4. Performs a QUIT to end the run.

This statement has the following format:

<<ERROR>> PROCEDURE
     statements

 {ENDPROC      } 
 {ENDPROCEDURE } 

<<ERROR>>

A reserved label. Most statements that refer to labels cannot reference it; however, a DO statement can reference it. For example, QUIT ERROR is an illegal statement, but DO ERROR is valid.

statements

The action that takes effect when an error occurs. The statements in the body of the error procedure can consist of any PDL statements needed to process the error. The last statement is commonly a QUIT or PROCESS NEXT statement. If neither of these statements is issued, the default error procedure runs after the coded error procedure.

A program can contain only one error procedure. It can be anywhere in the program, but if it is the first procedure, the next procedure becomes the main procedure. When a procedure other than the first procedure becomes the main procedure, you must name the main procedure.

You can code $ERROR functions in the error procedure to return information about the last error. These functions only return meaningful data in the error procedure or in a procedure or CA Ideal subprogram invoked by the error procedure. The $ERROR functions are available directly in a CA Ideal subprogram called from the error procedure‑you do not have to pass them as parameters. For more information regarding error handling, see the chapter “Error Handling“ in the Creating Programs Guide.

A QUIT statement without a label and a QUIT PROCEDURE statement are invalid in the error procedure because they imply a QUIT ERROR.

When an error with an $ERROR‑CLASS of SYS occurs, your error procedure does not receive control and the default error procedure is invoked.

A runtime error in the error procedure invokes the default error procedure.

Generally, the default error procedure sets the value of the $RETURN‑CODE function to 12 (unless it is already 12 or greater). The default error procedure runs after a coded error procedure that does not execute a QUIT RUN or PROCESS NEXT.