ON ERROR Command

Example   See Also

Specifies a command that executes when an error occurs.

Syntax

ON ERROR
  [Command]

Arguments

Command

Specifies the Microsoft Visual FoxPro command to execute. After the command executes, program execution resumes on the line immediately following the line that caused the error. However, if the error-handling procedure includes RETRY, the program line that caused the error is executed again.

If the command specifies a procedure to execute when an error occurs, you can use ERROR( ), MESSAGE( ), LINENO( ), and PROGRAM( ) to pass the error number, the error message, the program line number, and the program name to the procedure. This information can be used to correct the cause of the error.

Remarks

When an error occurs during program execution, Visual FoxPro executes the command you specify with ON ERROR. Typically, ON ERROR uses DO to execute an error-handling procedure.

Use ON ERROR without a command to restore the default Visual FoxPro error handler.

ON ERROR procedures cannot be nested. If ON ERROR is issued within an ON ERROR procedure, the default Visual FoxPro error handler is restored.