The information in this article applies to:
SUMMARYFoxPro provides the ON ERROR command to allow programmers to trap for specific errors that occur within applications. This article describes how to use a generic error trapping routine and shows an example in the context of testing a table for exclusive use.
MORE INFORMATIONIf certain FoxPro commands attempt to use a table that is not opened exclusively, these commands generate the error "Exclusive open of file is required." There are several Xbase commands that require the target table be opened exclusively. These commands include INDEX, INSERT [BLANK] (not INSERT SQL), PACK, REINDEX, MODIFY STRUCTURE, ALTER TABLE, and ZAP. The code example below illustrates a simple method of trapping this error and returning a custom message to the user. This basic example can be modified to handle other errors. Sample CodeCREATE TABLE junk (fld1 C(20)) FOR x = 1 to 2 INSERT INTO junk VALUES ("This is test data") ENDFOR ON ERROR DO errhand WITH error() && Activates ON ERROR routine CLOSE ALL USE junk SHARE ZAP PROCEDURE errhand PARAMETERS merror IF merror =110 IF _windows=.t. and ATC("Visual",VERSION())>0 =MESSAGEBOX("This procedure requires exclusive use of the table. ; Please try again ; later.",48,"My Custom Messagebox Title") ELSE WAIT WINDOW "This procedure requires exclusive use of the table. ; Try again later." ENDIF ENDIF USE DELETE FILE Junk.dbf ON ERROR && Turns off ON ERROR routine The user can use the MESSAGEBOX() function in FoxPro for Windows 2.x. However, the programmer must use the SET LIBRARY TO command to direct FoxPro to the FoxTools.fll file. Additionally, the user can use the FXALERT() function to display the message on FoxPro for the Macintosh 2.x. For more information about the MESSAGEBOX() and FXALERT()functions in FoxPro 2.x versions, please see the following articles in the Microsoft Knowledge Base:
Additional query words: Keywords : kbVFp300 kbVFp500 kbVFp600 kbVFP260 Version : Platform : Issue type : kbhowto |
Last Reviewed: August 20, 1999 |