Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to trap errors with ON ERROR while error event in pl
Message
From
03/05/2002 00:46:27
 
 
To
02/05/2002 23:05:47
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00618670
Message ID:
00652245
Views:
25
Mark,

Nice. It seems you've extended it a bit. I only 'redirect' the on('error') in the error event.


>Gregory, I really liked your method and used it in my wrapper class that calls my UDF. I didn't use this within a form. I just used your method of executing the ON ERROR setting from within an Error() event.
>
>It took me a while to figure out what you meant and what your example was doing, but I get it now. It seems to work nicely. Basically, I create a class that has two methods. One is the Error() event. The other is a method that calls my original UDF. After I create the object, I call the second method, which calls my UDF. When an error occurs in the UDF the Error event "macro's" the command that is returned from ON("ERROR"). That is slick! I'm so glad there is an easy and quick way to keep my existing UDF's in tact without major changes. Thanks a lot.
>
>For anyone's reference, here is the code I add to the top of my UDF's:
>
>----------------------------------
>Function myfunc
>
>o= CREATEOBJECT("myfunc")
>o.myfunc(m.tcParm)
>
>RETURN
>
>*/////////////////////////////
>DEFINE CLASS myfunc as Custom
>
>**********
>function myfunc
>* this calls the original UDF
>
>PARAMETERS m.tcParm
>
>DO myfunc_ WITH m.tcParm
>
>ENDFUNC
>
>**********
>PROTECTED function Error(m.tnError, m.tcMethod, m.tnLine)
>* Error event gets called on any Errors (ON ERROR's are ignored).
>
>LOCAL m.lcOnErr
>
>m.lcOnErr= ON("error")
>IF NOT EMPTY(m.lcOnErr)
> &lcOnErr
>ENDIF
>
>* put some code here to handle any errors in case an ON ERROR isn't set.
>
>ENDFUNC
>
>ENDDEFINE
>
>*////////////////////////////
>
>PROCEDURE myfunc_ && this was the original UDF. Added an '_' to rename it.
>
>PARAMETERS m.tcParm
>* original program continues from here.
>
>----------------------------------
>>
>>Mark,
>>
>>For what it is worth, this is the way I do it with forms
>>
>>normal on error : ON ERROR Error_(Error(), Program(), LineNo() )
>>
>>which starts with
>>
>>procedure Error_(nError, _program, _lineno  )
>>
>>
>>form.Error routine
>>
>>LPARAMETERS nError, _program, _lineno
>>
>>this.LockScreen = FALSE
>>assert nError==Error()
>>private  __Object_with_Error__	&& for error handler
>>private __LineNoPassed__	&& for error handler
>>
>>__Object_with_Error__ = this
>>__LineNoPassed__ =  _lineno
>>
>>
>>local s
>>s = on('error')
>>&s
>>
>>release __Object_with_Error__, __LineNoPassed__
>>
>>
>>In the error routine I test for the existance of __Object_with_Error__
>>
>>so the following routine works as expected, even in a form
>>
>>
>>private HadError
>>HadError = FALSE
>>local sError
>>sError = on('Error')
>>on Error HaddError = TRUE
>>
>>use SomeTable excl
>>on error &sError
>>
>>if( HadError )
>>
>>else
>>
>>
>>endif
>>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform