next up previous 211
Next: Setting and defining status values
Up: ERR - Error Reporting System
Previous: Overview


Inherited status checking

The recommended method of indicating when errors have occurred within Starlink software is to use an integer status value in each subroutine argument list. This inherited status argument, say STATUS, should always be the last argument and every subroutine should check its value on entry. The principle is as follows:

Here is an example of the use of inherited status within a simple subroutine:

      SUBROUTINE ROUTN( VALUE, STATUS )
      
*  Define the SAI__OK global constant.
      INCLUDE 'SAE_PAR'
      INTEGER STATUS

      ...

*  Check the inherited global status.
      IF ( STATUS .NE. SAI__OK ) RETURN

      <application code>

      END

If an error occurs within the ``application code'' of such a subroutine, then STATUS is set to a value which is not SAI__OK, an error is reported (see below) and the subroutine aborts.

Note that it is often useful to use a status argument and inherited status checking in subroutines which ``cannot fail''. This prevents them executing, possibly producing a run-time error, if their arguments contain rubbish after a previous error. Every piece of software that calls such a routine is then saved from making an extra status check. Furthermore, if the routine is later upgraded it may acquire the potential to fail, and so a status argument will subsequently be required. If a status argument is included initially, existing code which calls the routine will not need to be changed (see further discussion of this).



next up previous 211
Next: Setting and defining status values
Up: ERR - Error Reporting System
Previous: Overview

MERS (MSG and ERR) Message and Error Reporting Systems
Starlink User Note 104
P C T Rees
A J Chipperfield
22 October 2001
E-mail:ussc@star.rl.ac.uk

Copyright © 2001 Council for the Central Laboratory of the Research Councils