Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help using 'return to program' with methods vs. function
Message
De
16/08/2001 09:58:40
Charlie Schreiner
Myers and Stauffer Consulting
Topeka, Kansas, États-Unis
 
 
À
15/08/2001 19:00:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00543789
Message ID:
00544666
Vues:
25
Hi Malcolm,
I'm not sure I fully appreciate what you want to do. But here are my thoughts anyway. It seems like you want the ErrorHandler to return to a specific method in the stack. That seems like a job for the object itself, not some application wide ErrorHandler.
Why not have a TryCatchFinally object?
Example:
oTest = NEWOBJECT("MyTest")
oTest.Try("MyTableName")
RETURN

DEFINE CLASS MyTest AS TryCatchFinally
   PROCEDURE Try (FileName)
       USE (m.FileName) EXCLUSIVE
       RETURN DODEFAULT()
   ENDPROC
   
   PROCEDURE Catch
      IF This.oError.Number = X
         WAIT WINDOW "Sorry"
      ELSE
         * Do Nothing.
      ENDIF
   ENDPROC
ENDDEFINE

* Abstract Class.
DEFINE CLASS TryCatchFinally AS Relation
   oError = .NULL.

   PROCEDURE Try()
      * Write the Try block here in the subclass.
      RETURN ISNULL(This.oError) AND This.Finally()
   ENDPROC

   PROCEDURE Catch()
       * Write the code to run when the Try fails.
   ENDPROC

   PROCEDURE Finally()
      * Write code to run when all is well.
   ENDPROC

   PROCEDURE Error ( nError, cMethod, nLine )
      IF ISNULL(This.oError)
         This.oError = NEWOBJECT('ErrorInfo')
         This.oError.Save( m.nError, m.cMethod, m.nLine, This.Name )
      ENDIF
      This.Catch()
   ENDPROC
ENDDEFINE

DEFINE ErrorInfo AS Relation
Tag = "ErrorObject"
ErrorNumber = 0
ErrorMessage = ""
ErrorCodeLine = ""
ErrorLineNumber = 0
ErrorProgram = ""
ErrorName = ""

* Pass the error facts and this method saves them to this objects properties.
PROCEDURE Save (nError, cMethod, nLine, Name)
* Error method of an object might create this error
* object, then do a  This.oError.Save(m.nError, m.cMethod, m.nLine, This.Name)

  WITH This
   .ErrorNumber = IIF(VARTYPE(m.nError) = "N", m.nError, 0)
   .ErrorMessage = MESSAGE()
   .ErrorCodeLine = MESSAGE(1)
   .ErrorProgram = IIF(VARTYPE(m.cMethod) = "C", m.cMethod,'')
   .ErrorLineNumber = IIF(VARTYPE(m.nLine) = "N", m.nLine, 0)
   .ErrorName = IIF(VARTYPE(m.Name) = "C", m.Name, '')
  ENDWITH
ENDPROC

* Release this object.
PROCEDURE Release
   RELEASE This
ENDPROC
ENDEFINE
>>While you're at it, could you write up a request for 'Try/Catch/Finally' functionality? I have never done any real-world work in a language that supported it...
Charlie
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform