Load error handler

Command group Flag affected Reversible Execute on client Platform(s)
Error handlers NO YES NO All


Load error handler ([All libraries]) [name/]name (first-error-number, last-error-number)


All libraries If specified, the error handler applies to errors encountered in all libraries, rather than just the calling library


This command loads a specified method which handles errors which may occur within a library. You can specify a range of error codes to be handled by the handler by giving the first and last error number. If no range is specified, the handler is called for all errors. Errors are either Fatal or Warning.

Error codes such as kerrUnqindex, kerrBadnotation, kerrSQL, can also be used as parameters. The Catalog window lists all the constants available in Omnis.

Fatal errors

A fatal error is one that normally stops method execution and drops into the debugger if available. The error code #ERRCODE is displayed on the status line in the debugger and is greater than 100,000.

Warning errors

A warning error is one that does not normally quit the method nor report an error description. The error code #ERRCODE is displayed on the status line in the debugger, if invoked, and is less than 100,000.

The check box option All libraries is provided. If this is not checked, the handler is called only for errors encountered in the library which loaded the error handler. This command leaves the flag unaffected and is reversible; that is, the handler is unloaded when the command is reversed. An error handler remains loaded until it is unloaded or the library containing the handler method is closed. Error handlers loaded within an error handler always unload when that error handler terminates.

An alternative to using the parameters passed to the error handler, is to use the variables #ERRCODE and #ERRTEXT. However, you must copy the values of #ERRCODE and #ERRTEXT upon entry to the error handler, since commands you execute in the error handler might change their values.

An error handler can use one of the Set error action commands (SEA) to set what it requires the next action to be. If the error handler quits without making a Set error action and there is another handler capable of accepting the error, the second handler is called. Otherwise, the default action for the error is carried out, depending on whether it is a fatal error or warning.

If an error occurs within an error handler, that error is handled in the usual way except that the original error handler will not be used (even if it could handle that error). It is possible to load error handlers within an error handler; these are meant to deal with errors within the handler and are unloaded automatically when the error handler completes execution.


; pCode is defined as a Long Integer
; pText is defined as a character type
; A typical error handler
If pCode=kerrBadnotation
  ; handle error - pText contains a string describing the error
End If
; The following example handles the error returned by the data manager when an attempt to
; duplicate a unique index occurs on update:
Load error handler cMyErrorHandler/Errors
Prepare for edit
Enter data
Update files if flag set
; In the method Errors of code class cMyErrorHandler
If pCode=kerrUnqindex
  OK message Error (Icon) {You have entered a duplicate field value/'X' has been appended to your entry}
  Calculate iValue as con(iValue,'X')
  Enter data
  If flag true
    SEA repeat command
    SEA continue execution
  End If
End If