Skip to content
Tcl Source Code View Ticket
Login

View Ticket

add examples to the [catch] man page

Closed / Works For Me2142989fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-10-02 19:32:29
I use tcl-8.5.4.

In the following code 'catch' returns 1 indicating an error but '::errorInfo' isn't set, producing 'no such variable' message.


--- testcase ---
proc c {} {}
proc main {} {
  if {[catch { return [c] }]} {
    puts "ERROR: *$::errorInfo* *************"
  }
}
main

--- output ----
can't read "::errorInfo": no such variable
    while executing
"puts "ERROR: *$::errorInfo* *************""
msoferplain2008-10-03 02:46:25
Wrong diagnostic: [catc] is not returning 1 (error) but 2 (return); no error, no errorInfo ...
 mig@oli:~$ tclsh
 % proc c {} {}
 % catch {return [c]}
 2
yurivictplain2008-10-03 04:43:38
Makes sense: 'catch' has 5 possible return values (0..4).

Then I suggest you add another example of basic 'catch' usage in EXAMPLES section of catch(n) demonstrating all 5 return values.
Otherwise people look at the example (if {[catch...]} {...exit...}) and get misled by it's simplicity.
msoferplain2008-10-03 05:07:28
Catch can return a lot of other codes - essentially, any 32-bit integer value:
 % catch {return -code 1234 -level 0}
 1234
If you have a suggestion on how to improve the man page and examples, please add it here.
dkfplain2009-04-05 00:09:01
Might also want to try the [try] command in 8.6
sf-robotplain2009-04-19 09:21:06
allow_comments - 1

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.