The article directories
-
$ECODE variable
-
describe
-
Remove ` $ECODE `
-
Setting $ECODE
-
The ‘$ECODE’ string overflows
-
Pay attention to
-
- Create your own error code
$ECODE variable
Contains the current error code string.
The outline
$ECODE
$EC
Copy the code
describe
When an error occurs, the Cache sets the $ECODE special variable to a comma-separated string containing the error code corresponding to the error. For example, when referencing an undefined global variable, the Cache sets the $ECODE special variable to the following string:
,M7,
Copy the code
$ECODE can contain ISO 11756-1999 standard M error codes in the format M #, where # is an integer. For example, M6 and M7 are “undefined local variables” and “undefined global variables” respectively. (M7 is dedicated to global variables and processes.)
$ECODE can also contain the same error code as the Cache General System error code (the error code returned to the $ZERROR special variable at the terminal prompt). However, $ECODE prefixes these error codes with a “Z” and removes Angle brackets. So $ECODE error ZSYNTAX is a
error, ZILLEGAL VALUE is a
error, and ZFUNCTION is a
error. $ECODE does not reserve any additional error messages for the error codes that provide it; So ZPROTECT is a
If an error occurs when $ECODE already contains the previous error code, the existing error stack is cleared when a new error occurs. The new error stack will contain only entries that show the state at which the current error occurred. (This is different from the earlier $ECODE behavior, where the old error stack persisted until it was explicitly cleared.)
If there are multiple error codes, the Cache appends each error code to the end of the current $ECODE value in the order in which it was received. Each error in the resulting $ECODE string is separated by commas, as shown below:
,ZSTORE,M6,ZILLEGAL VALUE,ZPROTECT,
Copy the code
In this case, the most recent error is the
You can also explicitly clear or set $ECODE. Always clear $ECODE when terminating the current process.
remove$ECODE
You can clear it by setting $ECODE to an empty string (“”), as follows:
SET $ECODE=""
Copy the code
Setting $ECODE to an empty string produces the following effect:
- It clears all existing ones
$ECODE
Value. It’s on the existing$ZERROR
The value has no effect. - It clears the error stack for the job. This means that
$STACK
Subsequent calls to the function return the current execution stack, not the last error stack. - It affects
$ETRAP
Error handling control flow for the error handler.
You cannot create a new $ECODE special variable. Attempting to do so produces a
error.
Setting $ECODE
You can enforce an error by setting $ECODE to a value that is not an empty string. Setting $ECODE to any non-null value forces an interpreter error during the execution of the ObjectScript routine. After the Cache sets $ECODE to the specified non-null value, the Cache takes the following steps:
- Writes the specified value to
$ECODE
Overrides all previous values. - generate
<ECODETRAP>
Error. (this will$ZERROR
Set to the value<ECODETRAP>
). - Pass control to any error handlers that have been established. The error handler can check the selected
$ECODE
String values and take steps to properly handle the condition.
$ECODE
String overflow
If the cumulative string in $ECODE exceeds 512 characters in length, the error code that caused the string overflow is cleared and replaced with the current list of error codes in $ECODE. In this case, the list of errors in $ECODE is the list of errors since the last string overflow, starting with the error that caused the overflow.
Pay attention to
Create your own error code
The format of the $ECODE special variable is a comma-surrounded list of one or more error codes. Error codes beginning with the letter U are reserved for users. All other error codes are reserved for the Cache.
The user-defined $ECODE value should be different from the value automatically generated by the Cache. To ensure this, always precede the error text with the letter U. Also, remember to use commas to describe error codes. Such as:
SET $ECODE=",Upassword expired! ,"
Copy the code
Check for Cache errors with $ZERROR instead of $ECODE
The error handler should check $ZERROR, not $ECODE, for the most recent Cache error.