Suppose you have an application management object assigned as the core property of the global _app object. The following ON ERROR command specifies a particular method of that object to act as a global error handler; a method call is a valid statement. It passes all relevant error information to the method as parameters:

on error _app.core.globalErrorTrap(program(), lineno(), error(), message())

The ON ERROR handler can then display an error message and terminate the application, like this:

function globalErrorTrap(cProg, nLineno, nError, cMsg)

   local c 

   #define CHAR_CR chr(13) 

   c = cMsg + CHAR_CR + CHAR_CR + ; 

   "In: " + cProg + CHAR_CR + ; 

   "Line: " + nLineno + CHAR_CR + CHAR_CR + ; 

   "If this error persists, contact program vendor." 

   msgbox(c, "Unexpected Application Error [" + nError +"]", 16) 

   quit