Error Handling

errchk


In Example 3.3, the iferr block catches an error in a procedure that it calls directly, geomean. It is possible, however, for the error to occur in a subroutine that is called indirectly, that is, called by the called procedure. In order for the iferr block to check for these errors, an errchk statement must be added to each of the procedures between the procedure with the iferr block and the procedure which contains the error() call. The errchk statement is placed in the declarations section of the procedure and has the following syntax:

errchk list of procedure names
When an error occurs in a procedure whose name is listed in an errchk statement, program execution in the calling procedure jumps to the return statement. Thus the rest of the code in the calling procedure is skipped. By including errchk statements in all of the routines between the procedure with the iferr block and the procedure which contains the error() call, program execution will return to the iferr block without executing any intervening code if the error() procedure is called.
Example 3.4 shows the use of the errchk statement. The lowest level procedure, gtdist, computes the distance between two points. If this distance is zero, it calls the error() procedure. The intermediate level procedure, gtinv, computes the inverse of the distance. To prevent the procedure from trying to compute the inverse of zero, the procedure contains an errchk statement for gtdist. This causes the execution of the program to skip this statement and return to the iferr block in gtline.






Generated with CERN WebMaker