Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Design question - how to interrupt process
Message
From
01/06/2005 14:43:25
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01018971
Message ID:
01019072
Views:
21
I readed the VFP Help file on TRY CATCH, and it states that the ERROR event will catch the objects error before the CATCH statement. In otherwords, if there is a Error event, it will process the error first. I also saw no means to raise the error to the CATCH statement from the Error event. But, if there is no Error event defined in the object, the CATCH statement does process the error.


From the Error event help
Any errors that occur in an object's Error event must be handled by the object and are not escalated to an ON ERROR routine or TRY...CATCH...FINALLY handler.



>Hi Greg,
>
>Sounds like a good idea, I like it. If I would have some code in Error method of my object, would it still work?
>
>Thanks.
>
>>Hi Nadya,
>>
>>I see you are using VFP 8.0.
>>
>>Well TRY CATCH to the rescue.
>>
>>Do not have the obect destory itself premiturely. Perform it as a FINALLY operation and let the CATCH blocks process any errors the process throws.
>>
>>
>>SET STEP ON
>>
>>*-- Create the Object.
>>ox = CREATEOBJECT("DoThis")
>>
>>TRY
>>	*-- Run your process
>>	ox.RunThis()
>>
>>CATCH TO oError
>>	*-- Process the error message
>>	*-- The ErrorNo will always be 1098
>>	? oError.Message
>>FINALLY
>>	*-- Release the Object.
>>	ox=null
>>ENDTRY
>>
>>*================
>>
>>DEFINE CLASS doThis as Custom
>>
>>	PROCEDURE RunThis
>>		*-- do somthing and fail.
>>		LOCAL i
>>		*-- start of method
>>		FOR i=1 TO 10
>>			?? "."
>>		NEXT
>>
>>		*-- something happens, and the method fails,
>>		*-- so call ERROR with your cError message
>>		ERROR "My method failed"
>>		
>>		*-- Because the ERROR raised the error, and the CATCH caught it.
>>		*-- This part of the method is not ran.
>>		FOR i=1 TO 10
>>			?? "."
>>		NEXT
>>
>>	ENDPROC
>>	
>>ENDDEFINE
>>
>>
>>
>>
>>>Hi everybody,
>>>
>>>I'm creating a custom class called BusinessProcess. In this class I'm going to have RunProcess method. If some error conditions occur, I want to be able to stop the process immediatelly.
>>>
>>>I have cError property. If I set this property to something, it means, I have an error and want to stop. My question is: is it advisable to create a custom Release method (call Destroy() in it) and call this method in cError_Assign?
>>>
>>>Or there are better ideas?
>>>
>>>Thanks in advance.
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform