.
.
Name
Catch-execute the script and capture errors
Syntax
Catch Script?Resultvarname? ?Optionsvarname?
Description
CatchCommand to prevent the termination of script execution due to an error,CatchThe command can call the Tcl interpreter to execute the script and return the script normally.
If the script produces an error,CatchA non-zero integer is returned. If no error is captured0OrTcl_ OKTCL also defines four exception codes:1(Tcl_error),2(Tcl_return),3(Tcl_break) And4(Tcl_continue). Returns an error when the script is executed.Tcl_error, Other exceptionsReturn,BreakAndContinueCommand generation.
IfResultvarnameVariable. When the returned value is1Stored inResultvarnameIs an error message.0, Stored inResultvarnameIs the script running result.
IfOptionsvarnameVariable, which contains-CodeAnd-LevelTwo entries. If the returned code is notTcl_return,-LevelIs0,-CodeReturns the Exception Code. When the returned code isTcl_return,-LevelAnd-CodeFor other values, seeReturnCommand.
WhenTcl_errorThree additional entries will be addedOptionsvarnameMedium:-Errorinfo,-ErrorcodeAnd-Errorline,-ErrorinfoAn entry is an error message,-ErrorcodeThe entries are some additional information about the error, which is stored as a list,-ErrorlineThe location where the error occurred.-ErrorinfoAnd-ErrorcodeAll entries are recent errors and can be used: ErrorinfoAnd: Errorcode.
Example
CatchThe command can beIfCommand.
if { [catch {open $someFile w} fid] } {
puts stderr "Could not open $someFile for writing/n$fid"
exit 1
}
InReturnThe command has more information aboutCatch.