|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Error Handling > AIU. - Artificial Intelligence Utility |
MiniRobotLanguage (MRL)
AIU.GetLastError
Retrieves the last AIU-specific numeric error code.
Intention
The AIU.GetLastError command (aliased as AIU.Glerr) is a fundamental tool for debugging and error handling in your scripts. After an AIU command fails or produces an unexpected result, this command allows you to retrieve the specific numeric error code that was generated. This code provides a precise reason for the failure, such as a missing API key, a failed HTTP request, or a JSON parsing error.
It’s your robot’s diagnostic tool—AIU.GetLastError tells you the exact error number so you can build robust scripts that react to problems correctly.
Illustration
┌──────────────────────────────┐
│ AIU.Ask (Fails) │
├──────────────────────────────┤
│ ❌ No API Key Set │
├────────────────────┬─────────┤
│ AIU.GetLastError │ Result │
├────────────────────┼─────────┤
│ Checks Error... │ 101 │
└────────────────────┴─────────┘
Retrieving the numeric code after a command fails.
Syntax
AIU.GetLastError[|$$RET]
Parameter Explanation
P1 - $$RET - (Variable, String, Optional)
The variable where the numeric error code will be stored. If omitted, the code is returned on the top-of-stack (TOS).
Examples
'***********************************
' AIU.GetLastError - Sample 1: Checking for a specific error
'***********************************
AIU.SetKey|
AIU.Ask|Hello|$$RES
AIU.GetLastError|$$ERR
' %AIU_ERR_API_KEY_MISSING is 101
JIV.$$ERR=101|Lab_Key_Missing
MBX.An unexpected error occurred.
END.
:Lab_Key_Missing
MBX.Error:|Please set the API key before making a request.
END.
Remarks
- The alias AIU.Glerr can be used for convenience.
- A return value of 0 (%AIU_ERR_NONE) indicates that the last AIU operation completed successfully without raising an AIU-specific error.
- Use this command in conjunction with AIU.GetLastErrorMsg to get both the numeric code and the human-readable message for logging or display.
See also: