catch
Catch errors from script evaluation.
Syntax
tcl
catch script ?resultVar? ?optionsVar?Parameters
- script: The script to evaluate
- resultVar: Variable to store the result or error message (optional)
- optionsVar: Variable to store options dictionary (optional)
Return Codes
| Code | Meaning |
|---|---|
| 0 | TCL_OK - Normal completion |
| 1 | TCL_ERROR - Error occurred |
| 2 | TCL_RETURN - return command |
| 3 | TCL_BREAK - break command |
| 4 | TCL_CONTINUE - continue command |
Options Dictionary
When using the optionsVar parameter, catch populates it with a dictionary containing detailed information about the script execution:
For Successful Execution
| Key | Description |
|---|---|
-code | The return code (0 for OK) |
-level | Return level (0 for normal) |
For Errors
| Key | Description |
|---|---|
-code | The return code (1 for ERROR) |
-level | Return level (0 for normal) |
-errorinfo | Human-readable stack trace |
-errorcode | Machine-readable error code (defaults to NONE) |
-errorstack | Call stack with argument values (INNER/CALL entries) |
-errorline | Line number where error occurred |
Global Variables
On error, catch automatically sets these global variables:
::errorInfo- Same content as-errorinfooption::errorCode- Same content as-errorcodeoption (defaults to NONE)
Examples
Output
Output
Output
