|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > JSON - Parser > Parser-Operations > !Utility and Conversion > PSJ. - JSON Operations |
SPR Script Language
PSJ.Errcode
Retrieves the last JSON library error code.
Intention
The PSJ.Errcode command in SPR retrieves the most recent error code generated by a JSON operation. Optionally, it stores this code in $$RET. It’s like asking your robot to tell you the last thing that went wrong while working with JSON.
For example, after a failed operation, it might return "2" to indicate a "not found" error.
Illustration
📝 Get Error Code: PSJ.Errcode retrieves the last error code.
📝 With Result: PSJ.Errcode|$$ERR stores the last error code in $$ERR.
Syntax
PSJ.Errcode[|$$RET]
Parameter Explanation
P1 - $$RET - (Variable, Numeric, Optional)
The variable to store the error code (e.g., $$RET as "$$ERR"). Returns 0 for no error or a positive value indicating the type of error. If omitted, the error code is returned but not stored.
Possible Return Values
- 0: No error
- 1: Invalid input or unknown type
- 2: Path or element not found
- 3: Syntax error in JSON input
- 4: Array index out of bounds
- 5: Type mismatch or unsupported type
- 6: Memory allocation error
- 7: Runtime error
- 8: General parsing error
- 9: Duplicate key in JSON object
- 10: Unexpected character or token
- 11: Limit exceeded
- 12: Error adding child node
- 13: Error duplicating subtree
- 14: Invalid node
Examples
'***********************************
' Sample 1: Get Last Error Code
PSJ.Errcode
' Retrieves the last error code
MBX.Ready
'***********************************
' Sample 2: Store Error Code
PSJ.Errcode|$$ERR
' Stores the last error code in $$ERR
IF $$ERR > 0 THEN PRT.Error Code: $$ERR ELSE PRT.No Error
MBX.Ready
Remarks
- $$RET returns 0 if no error has occurred; otherwise, it returns a positive value corresponding to the last error.
- The error code persists until the next JSON operation updates it.
Limitations
- Only reflects the most recent error; earlier errors are overwritten.
See also:
• PSJ.Free