error numbers
The error numbers assigned to ##ERROR have two parts.  $$ErrorObject is an unsigned byte value in the next to lowest byte that identifies the source of the error, while $$ErrorNature is an unsigned byte value in the low byte to identify the kind of error.   Error values assigned to ##ERROR are therefore:

  (($$ErrorObject << 8) + $$ErrorNature)

The $$ErrorObject and $$ErrorNature constants are defined in the standard library file "xst.dec".

programmer defined errors
Programs can combine their own error handling with the built-in error handling by assigning programmer-defined error numbers to ##ERROR whenever they detect an error. In this way, one quick

  IF ERROR(-1) THEN ...
  error = ERROR(0)
  IF error THEN ...

will test for any system or program generated detected error.

Consider a function that opens a file and reads some formatted data.  If there are errors opening the file or reading it, the function could simply RETURN and expect the calling function to find the error in ##ERROR.  On the other hand, the function might not encounter errors opening, reading, and closing the file, but might find improperly formatted data in the file.

The function could return an error message in ##ERROR to indicate the error condition, for example:

  error = ERROR($$ErrorObjectFile << 8 OR $$ErrorNatureInvalidFormat)

If none of the pre-defined messages is appropriate, a program can define its own $$ErrorObject and/or $$ErrorNature constants to create its own error numbers.  These numbers should start at 255 and work lower to assure they won't conflict with values defined in later versions of the standard library.