In fact catch can get a little more but 0 and 1 are the most significant ones.
Catch can get:
0 TCL_OK normal return
1 TCL_ERROR error return
2 TCL_RETURN cause the *caller* to return
3 TCL_BREAK call [break] in the caller
4 TCL_CONTINUE call [continue] in the caller
And more: all codes returned with [return -code ...].
From the return entry of Tcl manual:
EXCEPTIONAL RETURNS
In the usual case where the -code option isn't specified the procedure will return normally (its completion code will be TCL_OK). However, the -code option may be used to generate an exceptional return from the procedure. Code may have any of the following values:
ok
Normal return: same as if the option is omitted.
error
Error return: same as if the error command were used to terminate the procedure, except for handling of errorInfo and errorCode variables (see below).
return
The current procedure will return with a completion code of TCL_RETURN, so that the procedure that invoked it will return also.
break
The current procedure will return with a completion code of TCL_BREAK, which will terminate the innermost nested loop in the code that invoked the current procedure.
continue
The current procedure will return with a completion code of TCL_CONTINUE, which will terminate the current iteration of the innermost nested loop in the code that invoked the current procedure.
value
Value must be an integer; it will be returned as the completion code for the current procedure.
I'm assuming that it's only a transcription error that you omitted the "$" in front of "fieleName" in the example where you tried to use the catch command. But I thought I'd point it out, just in case.
Anyway, as has been mentioned previously, all built-in Tcl commands that generate an error condition do so with a return code of "1" (which is the value that the catch command would return in this case). Successful execution is indicated by a return code of "0". In practice, you don't have to worry about other possible return codes unless you're creating your own control structures in Tcl. But the upshot is that the return code isn't going to help you much in debugging the error.
The general syntax of catch is:
[tt]catch actionvarName[/tt]
If the action executes without any error, the return value of the last command executed in the action is stored in the variable given by varName. In the case of an error, the error message is stored in varName.
So, when catch indicates an error, checking the value of varName will tell you what error occurred. The code fragment that marsd gave above should print out the error message if an error occurs when opening the file. Actually, his example could be simplified somewhat as:
What leads you to believe that open is returning an invalid file identifier? Personally, I can't think of any case in which Tcl's built-in open command would ever return an "invalid" file identifier. open can raise error conditions if it can't successfully open a file, but in that case, no file identifier is returned. Some situations that I can think of that might cause open to generate an error are:[ul][li]The file specified doesn't exist[/li][li]Your script doesn't have permission to read the file (or write to it, depending on the mode in which you're opening it)[/li][li]The file is in some way locked by another application[/li][/ul]If you could post the error message returned by open, perhaps someone here could figure out what's going wrong. - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.