Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try... this.error()... and then catch
Message
De
30/11/2004 17:36:06
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, États-Unis
 
 
À
23/04/2004 21:13:00
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00897769
Message ID:
00965896
Vues:
16
Dragan,

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
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform