ONERRGO

Contents


Onerrgo allows a label to be declared in a routine identifying where the routine shall be sent for execution in the event of an error.

 

Syntax

   Onerrgo [ label ] [ From routine ]

 

Parameters

Element

Description

Restrictions

label

Branch label in the event of error.

None.

routine

Routine in which the label is defined (the current routine by default), in one of the following forms:
nom_d'OBJet
'=' exp_nomtrt

The routine must be accessible.

exp_nomtrt

Alphanumeric expression whose result is the name of a routine.

The routine must be accessible.

 

Examples

   # File opened with error management (the existence
   # of the file should have been tested with the filinfo function) followed by a
   # calculation phase with branch to another routine.
    FLAG_ERREUR=0
    # If an error occurs, go to label PB_OUVERTURE
    Onerrgo PB_OUVERTURE From GESERR
    # Opening a sequential file
    Openi filpath("TXT","TEST","txt")
    # If an error occurs during the calculation phase
    Onerrgo PB_CALCUL
    Gosub CALCUL
    # No more branching now on error
    Onerrgo
    If FLAG_ERREUR
       # Stop if an error occurs
       End
    Endif
   #
    ... continuation of routine …
   #

(rest of previous example)
# Error management routines
   $PB_CALCUL
      Errbox "Error during calculation phase"-errmes$(errn)
      FLAG_ERREUR = errn
    Resume : # Return to line after the error
   #
   # Label defined in GESERR routine
   $PB_OUVERTURE
      Error "Problem opening file on line"-errl
      Error "Error no"-errn-":"-errmes$(errn)
      FLAG_ERREUR = errn
    Resume : # Return to line after the error

Description and comments

Onerrgo allows a label to be defined identifying where the routine shall be sent for execution in the event of an error. After the command Onerrgo, if an error occurs, the part of the routine following the label is executed.
In this error routine:

·         the function errn returns the error number;

·         the function errl returns the line number of the routine where the error occurred;

·         the function errm returns the second part of the error message;

·         the Resume instruction that ends an error routine is used to resume execution at the instruction following that where the error occurred;

·         between branching the error and the Resume, there is no re-branching to the label defined by Onerrgo if another error occurs (to avoid infinite loops in this case...).

The label called by Onerrgo, may be defined in another routine. Its name must then be specified in the instruction. This mechanism is used to form general error management routines.

Onerrgo without a label deletes the reference to a label in the event of an error; any error then causes a break in the routine and an error message is displayed.

An error management routine ends either with Resume or with End. In the former case, the routine interrupted by the error will resume at the instruction following that at which the error occurred. In the second case, the routine is not resumed.

 

Comments

Error management routines may not in any case terminate a transaction, whether by Commit or by Rollback, since it cannot be at the same location level as the routine that initiated it.

If a transaction is in progress when the error is detected, it is automatically cancelled (Rollback) if the routine closes with End. The user will be warned of this.

Errn error codes returned are positive integers of at least 5; in the reference manual these are all identified by a symbol followed by the numerical value of the error (for example "PAFIC (20)" for non-existent file error). In the programming manual, an annex gives the list of error symbols and numerical values. The errmes$ function also locates the error message for a given error code and the errm function specifies this.

An Onerrgo declaration remains valid as long as the routine is running (it is simply ignored between the moment the error routine starts and the Resume, but it resumes immediately afterwards).

As soon as an error management is done in a routine, it also acts in every sub-programme called by Call. However if a sub-programme does not include Onerrgo, and an error occures while it is running, the sub-programme stops, and the calling routine processes the error. If the error management routine ends with the Resume instruction, its execution will restart the calling routine's instructions, those of the sub-programme placed after that which caused the error being ignored (for an End, the calling routine is definitively concluded). It is therefore essential to use Onerrgo in a sub-programme called by Call and to manage its specific errors.

 

Associated errors

Error

Description

PAFIC (20)

Non-existent routine.

ERLAB (39)

Non-existent label (in the syntax "Onerrgo label", a non-existent label is detected when validating the routine).

ERMODE (10)

exp_nomtrt is not an alphanumeric expression expression.

 

Associated key words

END - RESUME - ERRN - ERRL - ERRMES$ - ERRM - CALL - ERRBOX]


CONTENTS


Copyright © Sage 1999 - 2007