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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only