Bagikan melalui


ERROR Command

Generates a Visual FoxPro error.

ERROR nErrorNumber | nErrorNumber, cMessageText1 | [cMessageText2]

Parameters

  • nErrorNumber
    Specifies the number of the error to generate. The standard Visual FoxPro error message is used when an error number is specified.

    For a list of Visual FoxPro error messages and their error numbers, see Error Messages A-Z.

  • cMessageText1
    Specifies the text displayed in an error message that supplies additional information about the error. For example, if you reference a memory variable that doesn't exist, Visual FoxPro supplies the name of the memory variable in the error message.

  • cMessageText2
    Specifies the text displayed in the error message. When cMessageText2 is specified instead of nErrorNumber, Visual FoxPro error number 1098 (user-defined error) is generated. Use a carriage return (CHR(13)) in cMessageText2 to move a portion of the error message to the next line.

Remarks

ERROR can be used to test error handling routines or to display custom error messages.

If an ON ERROR error handling routine is in effect when ERROR is issued, Visual FoxPro executes the ON ERROR routine. If an error occurs for an object, the object's Error event is executed.

If you issue ERROR from the Command window and an ON ERROR error handling routine is not in effect, Visual FoxPro displays the error message. If ERROR is issued in a program and an ON ERROR error handling routine is not in effect, Visual FoxPro displays the error message and allows you to cancel or suspend the program or ignore the error.

Note   The Error event does not occur if an ON ERROR routine is on the call stack.

Example

The following example generates three error messages. The first error message is the Visual FoxPro error message "Variable not found" (error number 12). The second error message again generates error 12, and includes a variable name of Myvariable. The last error message is a user-defined error message (error number 1089) "My error message."

ERROR 12  && Generates the Visual FoxPro error "Variable not found"
ERROR 12, 'Myvariable'  && Variable 'Myvariable' not found error
ERROR 'My error message'  && Generates 'My error message' error

See Also

ON ERROR | AERROR( ) Function | Debugging and Error Handling | Error Messages A-Z | Error Messages by Number