Leaving Routine in ON ERROR in FoxBASE+ or FoxProLast reviewed: April 29, 1996Article ID: Q88884 |
The information in this article applies to:
SUMMARYYou can use the following methods to leave the routine specified in an ON ERROR command:
MORE INFORMATIONThe ON ERROR command traps errors that occur during program execution. When an error occurs, the trap is triggered and the specified command is executed. An ON ERROR routine may be deactivated by issuing another ON ERROR command that does not specify a command to run. If the command specified in the ON ERROR command is DO <program>, specifying the ERROR(), LINENO(), MESSAGE(), and PROGRAM() functions as parameters passes the cause of the error, the line number where the error occurred, the error message, and the name of the program that had the error to the error handling function. This information can be valuable during the process of debugging an application. After the ON ERROR routine completes, program execution resumes on the line immediately following the line that causes the error. However, if the specified command is DO <program> and the <program> ends with a RETRY command, execution resumes on the line on which the error occurred. In FoxPro/LAN, an ON ERROR routine may be used to trap for errors created when a command that attempts to lock a record or a file is unsuccessful. If an ON ERROR routine is not in effect, FoxPro displays an error message that indicates why the record lock or file lock is unsuccessful (for example, "Record is in use by another"). If an ON ERROR routine is in effect, FoxPro does not display an error message and it executes the ON ERROR routine. Note that an unsuccessful lock attempt by the explicit locking functions [FLOCK(), LOCK(), and RLOCK()] does not trigger an ON ERROR routine or cause an error message to be displayed. Instead, these functions return a logical truth value (.F. or .T.) to indicate the failure or success of the lock attempt.
Sample Code
ON ERROR DO errhand WITH ; ERROR(), MESSAGE(), MESSAGE(1), PROGRAM(), LINENO() *** The next line should cause an error. *** USE nodatabase PROCEDURE errhand PARAMETER merror, mess, mess1, mprog, mlineno ? 'Error number: ' + LTRIM(STR(merror)) ? 'Error message: ' + mess ? 'Line of code with error: ' + mess1 ? 'Line number of error: ' + LTRIM(STR(mlineno)) ? 'Program with error: ' + mprog |
Additional reference words: VFoxWin 3.00 FoxDos FoxWin 1.00 1.01 1.02 2.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |