>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]')
&lcError
endif
Doug