try
try body ?handler ...? ?finally script?
Runs the body and then the first handler that matches its result. on CODE VARS SCRIPT matches a return code: ok, error, return, break, continue, or a number. trap PATTERN VARS SCRIPT matches an error whose error code starts with the list PATTERN. VARS names the variables for the result and the options. finally runs at the end in each case.
Examples
A click on an example runs it in the shell of the page.
try {expr {1 / 0}} trap {ARITH DIVZERO} {} {set r "no zero"}:no zerotry {set x 1} on ok {v} {set r "got $v"} finally {set f done}:got 1
Facts
- Capability: none.
- Compute cost: one compute unit for the call, and more for the commands that it runs.
Differences from Tcl 8.6
- The error of the compute limit goes through each handler and through
finally.