There may be many ''handler''s, each of which is described by 4 words. There are currently two types of handler defined: '''on''' ''code variableList script'': Exact matching of the exception code (i.e. the value returned by a [catch]). The code may be expressed as an integer or one of the following literal words: '''ok''', '''error''', '''return''', '''break''', or '''continue'''. Those literals correspond to the integers 0 through 4 respectively. '''trap''' ''errorPrefixList variableList script'': List-prefix matching of the [errorcode]. ** Documentation ** ***Manual Page*** http://www.tcl.tk/man/tcl8.6/TclCmd/try.htm ***Examples*** ** Examples ** This first example is from the manual page for try, and demonstrates testing for two different error conditions which might arise when attempting to [open] a file. [do...until in Tcl]: contains a nice example by [dkf] of using `try` in a [New Control Structures%|%new control structure]. try { set f [open /some/file/name] } trap {POSIX EISDIR} {} { puts {failed to open /some/file/name: it's a directory} puts "failed to open /some/file/name: it's a directory" puts {failed to open /some/file/name: it doesn't exist} puts "failed to open /some/file/name: it doesn't exist" ====== [AMG]: Here's an example of reraising an error: ====== try { set f [open /some/file/name] } on error {result options} { puts {something broke!} puts "something broke!" } ====== ** Use as a Shim ** **See also** * [throw] * [catch] * [error] * [return] [AMG]: [[try]] can be used to supply a full script where a single command (see [[command prefix]]) is expected. Simply give it a single argument, that being the entire script to run.