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 16:51:49
 
 
To
03/05/2002 00:46:27
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00618670
Message ID:
00652638
Views:
28
Thanks Gregory. I have to correct it a little. (I sometimes get too anxious to post something). Mainly, I took out the "PROTECTED" keyword on the Error function. PROTECTED can not be used on the Error() event since the UDF can't see the method if it's hidden. I'm including the corrected code below. This has really saved me a lot of time by allowing me to call existing UDFs that do their own ON ERROR error trapping within a Framework that uses Error() events, such as Codemine does. Promatrix doesn't use them. I wonder what the other frameworks use? Error events or ON ERRORs?

For anyone's reference, here is the code that I simply I add to the top of my UDF's. In this instance, my UDF has one parameter.

----------------------------------
FUNCTION myfunc

local o
o= CREATEOBJECT("myfunc")
o.myfunc(m.tcParm)

ENDFUNC

DEFINE CLASS myfunc as Custom

**********
function myfunc
* this calls the original UDF

PARAMETERS m.tcParm
MyOrigFunc(m.tcParm) && call the original UDF
ENDFUNC

**********
FUNCTION Error(m.tnError, m.tcMethod, m.tnLine)

LOCAL m.lcOnErr

m.lcOnErr= ON("error")
IF NOT EMPTY(m.lcOnErr) && if an ON ERROR was previously set
&lcOnErr && execute it
ELSE
* else handle any errors in case an ON ERROR isn't set.
ENDIF
ENDFUNC

ENDDEFINE

********************
PROCEDURE MyOrigFunc
* this is my original UDF
PARAMETERS m.tcParm

* an example of a part of my UDF that locally traps an error
local m.lcSavErr
private m.pnErrNo && this must be private since the on error command below will execute in the Error() event.

m.pnErrNo= 0 && init the error number
m.lcSavErr= ON("ERROR")
ON ERROR m.pnErrNo= ERROR()

error 1 && some code that generates an error

ON ERROR &lcSavErr
if m.pnErrNo <> 0
* locally handle my error
endif

return
--------------------------------
Previous
Reply
Map
View

Click here to load this message in the networking platform