Hi Doug & Mike,
I don't understand, where this code should be put. Say, we have several applications, which are class based or form based and use their own Error method. These applications can invoke UDFs, what in turn have something like
lcOldError = on('error')
on error do mycustomUDFProcedure
some code
on error &lcOldError
So, are you suggesting, what these applications (or Error form class, which they are based on, should have these lines at the top of Error method)?
Thanks in advance for your input.
>>You can't get ON ERROR to take precedence over an Error method of an object in the program stack. However, you could either move your code into method of a Custom class object, or wrap your UDF with an object, whose Error event method would then be usable for trapping errors as you intend. Even if you leave the code in a UDF and have a method of your wrapper object call it, the wrapper's Error event will catch any errors encountered in the PRG.
>
>To extend Mike's idea, the wrapper class' Error method could look at ON('ERROR') to see what error processing the UDF expected to do, and then explicitly call it. Here's an example:
lparameters tnError, tcMethod, tnLine
>aerror(laError)
>if not empty(on('ERROR'))
> lcError = upper(on('ERROR'))
> lcError = strtran(lcError, 'SYS(16)', '"' + tcMethod + '"')
> lcError = strtran(lcError, 'PROGRAM()', '"' + tcMethod + '"')
> lcError = strtran(lcError, ',ERROR()', ',tnError')
> lcError = strtran(lcError, ' ERROR()', ' tnError')
> lcError = strtran(lcError, 'LINENO()', 'tnLine')
> lcError = strtran(lcError, 'MESSAGE()', 'laError[2]')
> lcError = strtran(lcError, 'SYS(2018)', 'laError[3]')
>
>* Call the error handler.
>
> &lcError
>endif
Doug
If it's not broken, fix it until it is.
My Blog