Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with ON ERROR
Message
De
23/07/2001 16:58:57
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Problems with ON ERROR
Divers
Thread ID:
00534097
Message ID:
00534097
Vues:
38
I have been writing a utility to do some basic file fixes so that when I am away our other admin guy can at least handle some of the errors that happen if someone gets a dreaded "Not a table/dbf file" etc. Everything is pretty hunky dorey when the program runs as a standalone exe. In this case, the admin person can have all .dbfs checked in the directory or they can point and choose one by one.

In the middle part of the program, after a whole wack of checks that the file exists, that it is truly some sort of database table etc, I capture the basic file opening error with:

STORE 0 TO lnErrorNum

STORE ON("ERROR") TO lcOldOnError
ON ERROR STORE ERROR() TO lnErrorNum

USE (lcFileName) EXCLUSIVE

DO CASE

CASE lnErrorNum = 0
* nothing to do, stuff our return value...

CASE lnErrorNum = 15
* "Not a table/dbf" error, do our fix up here


Like I said, everything works great when run from an .exe. The hitch seems to come when I run this from a routine within the overall program. In that case, I already have an global error routine in effect. The modification I was doing to that routine was, if this is some sort of "fixable" table error (#15 above and a few others), that the global routine would then call this routine here passing in a file name; the "file fixer" routine, shown above, would then not do anything visual (like ask "do you want all files checked") and it would just go to the guts of the routine here - try to open the file, capture the error number and then try to fix it.

Problem is, my error line is not firing at all above; ie. when it gets to the

USE (lcFileName) EXCLUSIVE

I get the Foxpro message box showing me the error with Cancel, Ignore, Suspend (which obviously I don't want). When I go to the debugger and put in:

ON("ERROR")

It correctly shows "STORE ERROR() TO lnErrorNum" so it would appear that I have switched from my global handler to this el cheapo local one. The kicker also is, after I get the message box, if I say "suspend", I can then go out to the command box and type in

USE (lcFileName) EXCLUSIVE

and FoxPro does what it is supposed to do - stuff lnErrorNum. Finally, if I step through the code, the "STORE ERROR()..." code does indeed fire (but alas, it does not stuff lnErrorNum or it stuffs with zero as I think ERROR() gets reset to zero as soon as you go to another program.

Enough said. Note that this is running under FPW2.6 as I want to program to be cross-platform for an old app as well as some newer VFP apps. And the app that I tend to use it on a lot is a FPW app so not tested extensively on that.

Albert
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform