Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to handle errors
Message
From
27/11/2001 13:47:58
Charlie Schreiner
Myers and Stauffer Consulting
Topeka, Kansas, United States
 
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00586384
Message ID:
00586491
Views:
19
Hi Michelle,
Here's what I do in a base container class. I have an oError property that's set to an error object that holds the error number, etc.
LPARAMETERS nError, cMethod, nLine
* Create an object to store the errors.
This.oError = NEWOBJECT("lblError","Handler.VCX")
This.oError.Save(m.nError, m.cMethod, m.nLine, This.Name)
* When This.oError isn't .NULL., you know an error
* has occurred. Check for ISNULL(This.oError). To 
* reset to no error just say This.oError = .NULL.
IF VARTYPE(ThisApp) = "O" 
   This.oError.Populate(ThisApp.ErrorHandler)
   ThisApp.ErrorHandler.WriteToErrorLog()
ENDIF
LOCAL ErrMsg
ErrMsg = "ErrorNo=" +ALLTRIM(STR(m.nError)) + " " + " in Line = " ;
	+ ALLTRIM(STR(nLine)) + " of " ;
	+ This.Name + " " + PROGRAM(PROGRAM(-1)-2) + " " ; 
	+ This.oError.ErrorMessage
* This allows me to ignore, or, take a look, but in 
* a real app, ASSERTS are off.
ASSERT .F. MESSAGE m.ErrMsg 
RETURN
Then you can write code like this:
oUseMyTable = NEWOBJECT("UseTable", "Data.VCX")
oUseMyTable.Alias = "MyTable"
IF oUseMyTable.Open()
ELSE
   * What happened?
   * Check oUseMyTable.oError 
ENDIF
Many times I have return code that looks like this:
RETURN NOT ISNULL(This.oError)
>I think I'm not being clear. Maybe because I'm rather confused by all this myself. :)
>
>Anyway, I don't want to return false, I want to return my result object. That part I can handle. The part I am having trouble with is letting the code that caused the error know an error has occured. The old way I would have done it is like this:
>
>
>PUBLIC glWasError
>ON ERROR glWasError = .T.
>USE tablename
>ON ERROR
>IF glWasError
>  *-- Use AERROR to get the info and then deal with it
>ENDIF
>
>
>With doing things the OOP way, I don't have the ON ERROR anymore. Instead, if the USE fails, it goes to the error method.
>
>So I have:
>
>
>USE tablename
>IF ?????  && An error occurred
>  loResult.lSucceded = .F.
>  loResult.cError = ???????
>ELSE
>  loResult.lSucceded = .T.
>ENDIF
>
>RETURN loResult
>
>
>What I don't know is how to make the IF statement know there was an error and what that error is.
>
>Thanks,
>
>Michelle
>
>
>>Hi Michelle,
>>
>>How about returning a .F. from the DataOpen Method? Passing the return value (.F. in this case) up the calling chain. Your error handler can trap the error and do whatever action you require.
>>
>>Robert
Charlie
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform