|
<< 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.ClearError
Clears the last recorded AIU error and optionally the entire error history.
Intention
The AIU.ClearError command (aliased as AIU.ClrErr) is used to reset the library's error state. By default, it clears the most recent error code and message retrieved by AIU.GetLastError and AIU.GetLastErrorMsg. This is useful in error handling routines within your script after you have logged or dealt with a specific error, ensuring that old error states do not interfere with subsequent operations.
Optionally, you can also clear the entire session's error history log.
Illustration
┌────────────────────────┐
│ Error State (Before) │
├────────────────────────┤
│ Code: 101, Msg: "..." │
├────────────────────────┤
│ AIU.ClearError │
├────────────────────────┤
│ Error State (After) │
├────────────────────────┤
│ Code: 0, Msg: "" │
└────────────────────────┘
Resetting the library's error status.
Syntax
AIU.ClearError[|$$FLG]
Parameter Explanation
P1 - $$FLG - (Variable, numeric, Optional)
A flag to control history clearing. If $$FLG is set to 1, the entire error history log is also cleared. If omitted or 0, only the last error code and message are cleared.
Examples
'***********************************
' AIU.ClearError - Sample 1: Clear last error
'***********************************
AIU.Ask|Tell me a joke|$$RES
AIU.GetLastError|$$ERR
JNZ.$$ERR|Handle_Error
MBX.Success:|$$RES
END.
:Handle_Error
AIU.GetLastErrorMsg|$$MSG
MBX.An error occurred:|$$MSG
' Clear the error so the script can continue
AIU.ClearError
AIU.GetLastError|$$ERR ' $$ERR will now be 0
END.
'***********************************
' AIU.ClearError - Sample 2: Clear last error AND history
'***********************************
AIU.ClearError|1
AIU.GetErrorHistory|$$HIS
MBX.History:|$$HIS ' This will be empty
END.
Remarks
- This command is essential for robust scripting, allowing you to manage the error state after handling a failed operation.
See also: