Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try... this.error()... and then catch
Message
From
30/11/2004 18:00:13
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
30/11/2004 17:36:06
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00897769
Message ID:
00965903
Views:
16
OK, so the behavior fires for member objects, but not for property objects... which sort of makes sense, since the latter is actually an independent object, just referenced by the property, and doesn't have a .parent which would feel obliged to trigger its .error when such thing happens.

I was quite satisfied with the GetKey() method, so I really didn't investigate further. Thanks for taking this further :).

>I just ran into this same problem and found your thread.
>
>I prefer searching the collection only once and hence did not want to test with GetKey, nor could I use global variables as the class must be instantiated multiple times. I played around with your example and found another way around the problem.
>
>In your HasACollection object, if instead of declaring the collection as a member object, a variable is declared and assigned a collection object in the Init event, then the Error event is not fired in the Try block:
>
>
>ox=CreateObject("Testcaller")
>
>Define Class testcaller As Custom
>
>	Procedure Init
>		This.AddObject("member","hasACollection")
>		this.member.setparams("Parametername","SomeValue")
>	Endproc
>
>	Procedure Error(nError, cMethod, nLine)
>		Messagebox("TestCaller")
>	Endproc
>
>Enddefine
>
>
>Define Class HasACollection As Custom
>*!*		Add Object oParams As Collection
>	oParams = .null.
>	>	procedure init
>		this.oParams = createobject("Collection")
>	endproc
>	>	Procedure Error(nError, cMethod, nLine)
>		Messagebox("HasACollection")
>	Endproc
>
>	Procedure SetParams(cName, uValue)
>		Try
>			oItem=This.oParams.Item(cName)
>			messagebox("Missed")
>		Catch To oExc when oExc.ErrorNo = 2061
>			messagebox("Caught")
>		Endtry
>	Endproc
>Enddefine
>
>
>...Jim
>
>>>Dragan,
>>>
>>>Can you put together a small repro code that shows the problem?
>>
>>Here it is, as simplified as can. Both classes (caller and the one with a collection) have their own error methods. First time I had this (earlier this afternoon), the caller's error code was executing; now with this example it's the method of the class where it happens - don't know what caused the difference. Still, it happens in try block, which I think shouldn't happen.
>>
>>
ox=CreateObject("Testcaller")
>>
>>Define Class testcaller As Custom
>>
>>	Procedure Init
>>		This.AddObject("member","hasACollection")
>>		this.member.setparams("Parametername","SomeValue")
>>	Endproc
>>
>>	Procedure Error(nError, cMethod, nLine)
>>		Messagebox(Program())
>>	Endproc
>>
>>Enddefine
>>
>>
>>Define Class HasACollection As Custom
>>	Add Object params As Collection
>>
>>	Procedure Error(nError, cMethod, nLine)
>>		Messagebox(Program())
>>	Endproc
>>
>>	Procedure SetParams(cName, uValue)
>>		Try
>>			oItem=This.params.Item(cName)
>>			oItem.Value=uValue
>>		Catch To oExc
>>			oItem=Createobject("empty")
>>			AddProperty(oItem,"name", cName)
>>			AddProperty(oItem, "value", uValue)
>>			This.params.Add(oItem, cName)
>>		Endtry
>>	Endproc
>>Enddefine
>>

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform