IFERROR Test result code and conditionally branch to label |
Top Previous Next |
This script command checks the result of the previously executed command to see if IFERRORxx [ rcode ] is true. If so, the script file branches to [ label ], otherwise execution continues with the next command. The following variations of the IFERROR command are supported:
Syntactically, no space is permitted to the left of the ‘!’, '=', '<' or '>' symbols, and a space is required to the right of these symbols.
Consider the following example where execution branches to the :next label if the result code is greater than 1046:
IFERROR> 1046 GOTO next
In the following example execution branches to the :halt_error label if the result code indicates any error (non-zero result):
IFERROR!= $ERROR_SUCCESS GOTO halt_error
The [ rcode ] may be omitted if you do not wish to test for a specific error condition. A value of 1 is assumed, which results in testing for any error condition. The next example is functionally equivalent to the previous example:
IFERROR GOTO halt_error
The usefulness of the IFERROR command extends beyond simple error handling. In the following example, we construct a simple download loop by using IFERROR to catch a specific result code returned by the FTPGETFILE command that indicates there are no more files. In this case we are determining when to exit the loop rather than reacting to an error condition:
:fetch_file FTPGETFILE "*" IFERROR= $ERROR_NO_FILE_FOUND GOTO no_more_files RCVFILE %sitefile GOTO fetch_file :no_more_files
Related Command(s): LOOPIF, GOTO See also: Script File Result Codes, %lasterror |