1mNAME0m
       catch - Evaluate script and trap exceptional returns

1mSYNOPSIS0m
       1mcatch 4m22mscript24m ?4mvarName24m?


1mDESCRIPTION0m
       The  1mcatch  22mcommand may be used to prevent errors from aborting command
       interpretation.  1mCatch 22mcalls the Tcl interpreter recursively to execute
       4mscript24m,  and always returns without raising an error, regardless of any
       errors that might occur while executing 4mscript24m.

       If 4mscript24m raises an error, 1mcatch 22mwill return a non-zero  integer  value
       corresponding to one of the exceptional return codes (see tcl.h for the
       definitions of code values).  If the 4mvarName24m argument  is  given,  then
       the  variable  it  names  is set to the error message from interpreting
       4mscript24m.

       If 4mscript24m does not raise an error, 1mcatch 22mwill return 0 (TCL_OK) and set
       the variable to the value returned from 4mscript24m.

       Note  that  1mcatch  22mcatches all exceptions, including those generated by
       1mbreak 22mand 1mcontinue 22mas well as errors.  The only  errors  that  are  not
       caught  are  syntax  errors found when the script is compiled.  This is
       because the catch command only catches errors during runtime.  When the
       catch  statement  is  compiled,  the script is compiled as well and any
       syntax errors will generate a Tcl error.


1mEXAMPLES0m
       The 1mcatch 22mcommand may be used in an 1mif 22mto branch based on  the  success
       of a script.

              if { [catch {open $someFile w} fid] } {
                  puts stderr "Could not open $someFile for writing\n$fid"
                  exit 1
              }
       The  1mcatch  22mcommand  will  not catch compiled syntax errors.  The first
       time proc 1mfoo 22mis called, the body will be compiled and a Tcl error will
       be generated.

              proc foo {} {
                  catch {expr {1 +- }}
              }


1mKEYWORDS0m
