interp cancel
Stops the script that runs in an interpreter with an error.
interp cancel ?-unwind? ?--? ?PATH? ?RESULT?
Description
Stops the script that runs in the interpreter of PATH, or in the current interpreter with no PATH, with the error eval canceled and the -errorcode TCL CANCEL ICANCEL {eval canceled}. With RESULT, the message is RESULT and the last word of the -errorcode is RESULT.
The error comes at the next command that the canceled script starts after the cancel, so a cancel through an alias stops the script at the command after the alias. A catch in the canceled script stops the error, and the script goes on after it. With -unwind, the error goes through each catch of the interpreter and is an error of the call that started the script, with the message eval unwound and the -errorcode TCL CANCEL IUNWIND {eval unwound}.
A script of the parent calls it through an alias of the child, or from another thread. A cancel of an interpreter that runs no script stops the next script of that interpreter. interp cancel with no PATH stops the script that calls it.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| PATH | interpreter path | {} | The interpreter to stop. |
| RESULT | string | none | The message of the error, in place of eval canceled. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-unwind | flag | none | Makes the error go through each catch of the interpreter. |
-- | flag | none | Ends the options. |
-unwind
Makes the error go through each catch of the interpreter.
The error eval unwound goes up through each catch and try of the canceled interpreter, and the call in the parent gets it.
% set d [interp create]; interp alias $d stop {} interp cancel -unwind $d; catch {interp eval $d {catch {stop; set x 1} m; set m}} r; set r
eval unwound% set e [interp create]; interp alias $e stop {} interp cancel -unwind $e; interp eval $e {catch {stop; set x 1}}
eval unwound
-errorcode TCL CANCEL IUNWIND {eval unwound}--
Ends the options.
The word after -- is PATH, also when it starts with -.
% interp create -- -k; interp cancel -- -kA flag has no value to check.
Returns
An empty string.
Examples
% set c [interp create]; interp alias $c stop {} interp cancel $c; interp eval $c {catch {stop; set x 1} m; set m}
eval canceled
# The child runs the next script.
% interp eval $c {set y 2}
2
% interp alias $c stop2 {} interp cancel $c bye; interp eval $c {catch {stop2; set x 1} m o; list $m [dict get $o -errorcode]}
bye {TCL CANCEL ICANCEL bye}
Errors
% interp cancel nope
could not find interpreter "nope"
-errorcode TCL LOOKUP INTERP nope
% interp cancel -bogus
bad option "-bogus": must be -unwind or --
-errorcode TCL LOOKUP INDEX option -bogus
% interp cancel a b c
wrong # args: should be "interp cancel ?-unwind? ?--? ?path? ?result?"
-errorcode TCL WRONGARGS
Facts
- Capability
interp. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1