Caché ObjectScript Reference
[Back] [Next]
Go to:

Contains the current error code string.
When an error occurs, Caché sets the $ECODE special variable to a comma-surrounded string containing the error code corresponding to the error. For example, when a reference is made to an undefined global variable, Caché sets the $ECODE special variable to the following string:
$ECODE can contain ISO 11756-1999 standard M error codes, with the form M#, where # is an integer. For example, M6 and M7 are “undefined local variable” and “undefined global variable,” respectively. (M7 is issued for both globals and process-private globals.) For a complete list, see ISO 11756-1999 standard M programming language error messages in the Caché Error Reference.
$ECODE can also contain error codes that are the same as Caché General System error codes (the error codes returned at the terminal prompt and to the $ZERROR special variable). However, $ECODE appends a “Z” to these error codes, and removes the angle brackets. Thus the $ECODE error ZSYNTAX is a <SYNTAX> error, ZILLEGAL VALUE is an <ILLEGAL VALUE> error, and ZFUNCTION is a <FUNCTION> error. $ECODE does not retain any additional error info for those error codes that provide it; thus ZPROTECT is a <PROTECT> error; the additional info component is kept in $ZERROR, but not in $ECODE. For more information about Caché error codes, see $ZERROR; for a complete list, see General System Error Messages in the Caché Error Reference.
If an error occurs when $ECODE already contains previous error codes, the existing error stack is cleared when the new error occurs. The new error stack will contain only entries that show the state at the time of the current error. (This is a change from earlier $ECODE behavior, where the old error stack would persist until explicitly cleared.)
If there are multiple error codes, Caché appends the code for each error to the current $ECODE value as a new piece in a string delimited by commas, as follows:
In the above case, the most recent error is a <PROTECT> error.
You can also explicitly clear or set $ECODE. $ECODE is always cleared when you terminate the current process.
Clearing $ECODE
You can clear $ECODE by setting it to the empty string (""), as follows:
   SET $ECODE=""
Setting $ECODE to the empty string has the following effects:
You cannot NEW the $ECODE special variable. Attempting to do so generates a <SYNTAX> error.
Setting $ECODE
You can force an error by setting $ECODE to an value other than the empty string. Setting $ECODE to any non-null value forces an interpreter error during the execution of a Caché ObjectScript routine. After Caché sets $ECODE to the non-null value that you specify, Caché takes the following steps:
  1. Writes the specified value to $ECODE, overwriting any previous values.
  2. Generates an <ECODETRAP> error. (This sets $ZERROR to the value <ECODETRAP>).
  3. Passes control to any error handlers you have established. Your error handlers can check for the $ECODE string value you chose and take steps to handle the condition appropriately.
$ECODE String Overflow
If the length of the accumulated string in $ECODE exceeds 512 characters, the error code that causes the string overflow clears and replaces the current list of error codes in $ECODE. In this case, the list of errors in $ECODE is the list of errors since the most recent string overflow, beginning with the error that caused the overflow. See Using Caché ObjectScript for more information about the maximum string data length.
Creating Your Own Error Codes
The format for the $ECODE special variable is a comma-surrounded list of one or more error codes. Error codes starting with the letter U are reserved for the user. All other error codes are reserved for Caché.
User–defined $ECODE values should be distinguishable from the values Caché automatically generates. To ensure this, always prefix your error text with the letter U. Also remember to delineate your error code with commas. For example:
   SET $ECODE=",Upassword expired!,"
Check $ZERROR Rather Than $ECODE for Caché Errors
Your error handlers should check $ZERROR rather than $ECODE for the most recent Caché error.
See Also