Using the %lasterror Variable

Top  Previous  Next

 

The %lasterror variable is initialized to the last error or completion code of the most recently completed script command. The corresponding error text is stored in the %lasterrormsg internal variable.

 

The following excerpt from the main console window demonstrates one use of this variable:

 

RCVFILE "does_not_exist"

CMD:        RCVFILE "does_not_exist"

*Receiving to "C:\Program Files\Robo-FTP 3.7\does_not_exist"

*Download failed. [1059]

DISPLAY %lasterror

CMD:        DISPLAY %lasterror

%lasterror = 1059

DISPLAY %lasterror

CMD:        DISPLAY %lasterror

%lasterror = 0

FTPSETERROR

CMD:        FTPSETERROR

*FTP result code. [450]

DISPLAY %lasterror

CMD:        DISPLAY %lasterror

%lasterror = 450

 

IMPORTANT

In the example above, each call to DISPLAY %lasterror shows a different value. On the first execution the value shown is the 1059 error code from the failed RCVFILE download attempt. On the second execution, the value shown is 0 (i.e. $ERROR_SUCCESS) which indicates no error on the execution of the first DISPLAY command. The third execution follows a call to FTPSETERROR which sets the value of %lasterror using the value of %ftplastresult (the last response from the remote server) which in this case happens to be 450.

 

If you want to use this value to report an error via email it is necessary to save the value in a script file variable so that it doesn't get reset by a subsequent command.

 

 

Related Command(s): IFERROR, FTPSETERROR

See also: %lasterrormsg, Internal Script Variables, Script File Result Codes, Interactive Debugging