Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error Handling in VFP 5.0a
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00080468
Message ID:
00112778
Vues:
42
Robert,

All of my first level subclasses derived from the VFP baseclasses have this Error method:

ObjError( this, nError, cMessage, nLine )

That's it, so every object routes the error on to a UDF where I can get as sophisticated as I want, which puts me in the debugger if it's my machine, or log the error and quit on the client machine. But it could dispatch the error onto a global error handler object, after first checking for it and instantiating it if necessary. Or it could dispatch the error on to the object's .Parent. Since VFP doesn't have multiple inheritance I find using the udf gives me the most flexibility with the smallest amount of duplicated code as possible.

You also have to realize that an overridden Error methods take precedence over an ON ERROR error handler. If the object has any code in the Error method anywhere in its inheritance tree the Error method will be called.

Where an individual control can safely handle and work around an "expected" possible error it's Error method looks like:
if ( nError = 123456 )
   * handle it
   return
else
   ParentClass::Error( this, nError, cMessage, nLine )
endif
There's maybe a dozen places in all of my apps where this happens, mostly I try and defensively code around things to keep "expected" errors from happening. For example testing to see if a file exists before trying to use it, if the file might not exist beforehand. I'd rather do that than handle the File Not Found error because it's usually too late fix the error by time it occurs.

>Thanks, but is there a way to get around this generically, without having to write error code for each object? .resettodefault? Or am I destined to have to write specific code to deal with every instance where I may have a faulty bit of code? If I simply return after running my error routine in most cases it will only return to the error routine on the succeeding lines having to deal with different error numbers for each case. That would be tricky. I would prefer to have a catch all, release the form and leave it in the program (.exe).
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform