Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

ERROR Command

Generates a Visual FoxPro error.

You can use the ERROR command to test error handling routines or to display custom error messages.


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 Listed Alphabetically.

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 does not 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. To move a portion of the error message to the next line, use a carriage return (CHR(13)) in cMessageText2.

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.

NoteNote

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

The following example generates three error messages. The first line of code displays the error "Variable not found" (Error 12):

ERROR 12  

The second line of code generates Error 12 again but includes the variable name MyVariable and displays "Variable 'MyVariable' not found":

ERROR 12, 'MyVariable' 

The third line of code displays a user-defined error message (Error 1098) "My error message."

ERROR 'My error message'
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.