Errors

From EuWiki

Jump to: navigation, search

The library, when encountering an error condition, will emit a warning, optionally convertible into an abort condition. The aborting is performed by issuing the invalid ?1/0 instruction. It also provides cleanup routines, which work very similar to the crash_routine() native instruction present in Eu v2.5 and later.

Warning or errors?

The library internally defines a number of warning codes, which are passe to the warnErr(sequence error_parms). The argument is either an error message, or a pair {error message,error code}.

If you define custom error codes, it is preferable that they do not conflict with the ones the library uses. The constant w32MsgNum is the recommended threshhold above which custop error codes can be defined.

Warnings can either

  • be suppressed (warning level 0)
  • display as possible errors, with an option to continue (warning level=1)
  • cause abnormal termination (warning level=2)

The setWarning(integer level) sets the current warning level and returns the former value. Allowable values are 0,1 and 2 respectively. Using any other value resets the flag to 1, its default value.

Application termination

The abortErr(sequence error_parms) procedure is used on fatal errors, whether directly by the library or your application, or indirectly because a warning was converted into an error. error_parms has the same format as for warnErr().

When this happens, any cleanup functions the user provided are run, most recently attached first. These functions return a continuation flag. The chain stops if the returned flag is -1, otherwise it proceeds.

These functions are called when the application terminates, and take the following arguments:

  • a sequence, normally an error message;
  • an integer, the error code (thisis 0 if no error)
  • the current control (this may be zero)
  • a flag: 1 if this is the last cleanup function to be called, else 0.

To attach a cleanup function, call attachCleanup(function_routine_id). Yhis function returns its argument if the latter is negative (hence invalid), else the current number of cleanup routines.

To remove a function, call detachCleanup(function_routine_id). This funtion returns -1 on failure, else the number of remaining cleanup routines.

Personal tools