Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
Error handling in classes
Versions des environnements
Folks
I have three kinds of error handler in my 100,000 line 162 .prg application. I have a global handler that reports where an error arises and is the default if nothing else traps an error. I have CLASS-level handlers that trap errors inside objects, and I have some TRY/CATCH blocks.
I don't like TRY/CATCH blocks much and for critical code exposed to unpredicatable environmental error sources (e.g. table damaged on USEing, server goes down etc), I use two techniques.
I put all params into a small data object and pass it to the Init procedure of a processing object. If processing succeeds fails a var in the data object is set, e.g. bSuccess = .T. If it fails the Error event says why and writes messages to the data object and sets bSuccess = .F.
If it's a simple matter, a Function can wrap such an object and simply return a result, or an error code on failure.
What is not solved elegantly is, having trapped an error, (i) stopping further code executing within the class (ii) returning control to a handling point in the code block where the object was created. For example:
TRY
o1 = CREATEOBJECT("Task1", oSomeData1)
o2 = CREATEOBJECT("Task2", oSomeData2)
o3 = CREATEOBJECT("Task3", oSomeData3)
CATCH
* handle all exceptions here
ENDCATCH
You can't get to the exception handling point without laborious flag testing after each line.
Any thoughts on this?
John Burton
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement