Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to trap errors with ON ERROR while error event in pl
Message
De
02/05/2002 23:05:47
 
 
À
12/02/2002 03:17:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00618670
Message ID:
00652226
Vues:
26
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
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform