catch - Online Linux Manual PageSection : n
Updated : 8.5
Source : Tcl
Note : Tcl Built-In Commands
NAMEcatch − Evaluate script and trap exceptional returns
SYNOPSIScatch script ?resultVarName? ?optionsVarName?
.\}
DESCRIPTIONThe catch command may be used to prevent errors from aborting command interpretation. The catch command calls the Tcl interpreter recursively to execute script, and always returns without raising an error, regardless of any errors that might occur while executing script. If script raises an error, catch will return a non-zero integer value corresponding to the exceptional return code returned by evaluation of script. Tcl defines the normal return code from script evaluation to be zero (0), or TCL_OK. Tcl also defines four exceptional return codes: 1 (TCL_ERROR), 2 (TCL_RETURN), 3 (TCL_BREAK), and 4 (TCL_CONTINUE). Errors during evaluation of a script are indicated by a return code of TCL_ERROR. The other exceptional return codes are returned by the return, break, and continue commands and in other special situations as documented. Tcl packages can define new commands that return other integer values as return codes as well, and scripts that make use of the return −code command can also have return codes other than the five defined by Tcl. If the resultVarName argument is given, then the variable it names is set to the result of the script evaluation. When the return code from the script is 1 (TCL_ERROR), the value stored in resultVarName is an error message. When the return code from the script is 0 (TCL_OK), the value stored in resultVarName is the value returned from script. If the optionsVarName argument is given, then the variable it names is set to a dictionary of return options returned by evaluation of script. Tcl specifies two entries that are always defined in the dictionary: −code and −level. When the return code from evaluation of script is not TCL_RETURN, the value of the −level entry will be 0, and the value of the −code entry will be the same as the return code. Only when the return code is TCL_RETURN will the values of the −level and −code entries be something else, as further described in the documentation for the return command. When the return code from evaluation of script is TCL_ERROR, four additional entries are defined in the dictionary of return options stored in optionsVarName: −errorinfo, −errorcode, −errorline, and −errorstack. \{.ev 2
.\} The value of the −errorinfo entry is a formatted stack trace containing more information about the context in which the error happened. The formatted stack trace is meant to be read by a person. The value of the −errorcode entry is additional information about the error stored as a list. The −errorcode value is meant to be further processed by programs, and may not be particularly readable by people. The value of the −errorline entry is an integer indicating which line of script was being evaluated when the error occurred. The value of the −errorstack entry is an even-sized list made of token-parameter pairs accumulated while unwinding the stack. The token may be ‟CALL”, in which case the parameter is a list made of the proc name and arguments at the corresponding level; or it may be ‟UP”, in which case the parameter is the relative level (as in uplevel) of the previous CALL. The salient differences with respect to −errorinfo are that: [1] it is a machine-readable form that is amenable to processing with [foreach {tok prm} ...], [2] it contains the true (substituted) values passed to the functions, instead of the static text of the calling sites, and [3] it is coarser-grained, with only one element per stack frame (like procs; no separate elements for foreach constructs for example). \{.ev 2
.\} The values of the −errorinfo and −errorcode entries of the most recent error are also available as values of the global variables ::errorInfo and ::errorCode respectively. The value of the −errorstack entry surfaces as info errorstack. \{.ev 2
.\} Tcl packages may provide commands that set other entries in the dictionary of return options, and the return command may be used by scripts to set return options in addition to those defined above.
EXAMPLESThe catch command may be used in an if to 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
}
There are more complex examples of catch usage in the documentation for the return command.
SEE ALSObreak(n), continue(n), dict(n), error(n), errorCode(n), errorInfo(n), info(n), return(n)
KEYWORDScatch, error, exception 0
Johanes Gumabo
Data Size : 18,040 byte
man-catch.nBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 2 / 202,949
Visitor ID : :
Visitor IP : 3.145.58.141 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (rof_escape_sequence_block|26|(null)|(null)|-1|141) (parse_manual_page_|249|catch.n|283/141|══─}─══|.══─}─══
) (htmlprn|149|catch.n|283/141|.══─}─══|.══─}─══
) (rof_escape_sequence|91|catch.n|283/142|\}|.\}
) (parse_manual_page_|249|catch.n|283/142|\}|.\}
) (rof_escape_sequence|91|catch.n|327/159/327/160|\{.ev 2 |\{.ev 2
) (rof_escape_sequence|91|catch.n|327/168|\} |.\}
) (parse_manual_page_|249|catch.n|327/168|\}|.\}
) (rof_escape_sequence|91|catch.n|356/159/356/160|\{.ev 2 |\{.ev 2
) (rof_escape_sequence|91|catch.n|356/168|\} |.\}
) (parse_manual_page_|249|catch.n|356/168|\}|.\}
) (rof_escape_sequence|91|catch.n|363/159/363/160|\{.ev 2 |\{.ev 2
) (rof_escape_sequence|91|catch.n|363/168|\} |.\}
) (parse_manual_page_|249|catch.n|363/168|\}|.\}
)