If using Tcl in interactive mode , in which I input the following:
set list {1 2 3 4 5}
set sum 0
foreach el $list {
set sum [expr $sum + $element]
}
it will show a piece of very terse info:
can't read "element": no such variable
but when I use
puts $errorInfo
it wil show:
can't read "element": no such variable
while executing
"expr $sum + $element"
("foreach" body line 2)
invoked from within
"foreach el $list {
set sum [expr $sum + $element]
}"
which is what I really want.
The problem is : in non-interactive mode when I want to catch this error and then puts the errorInfo to get a stack trace, it'll merely display the terse info. How can I get the detailed stack trace like above? Thanks a lot!
Edited to add more details
say I have following code:
proc test1 {} {
set list {1 2 3 4 5}
set sum 0
foreach el $list {
if {[catch {set sum [expr $sum + $element]} err]} {
puts $::errorInfo
}
break
}
}
proc test2 {} {
foreach el $list {
set list {1 2 3 4 5}
set sum 0
set sum [expr $sum + $element]
}
}
#test1
#test2
If I uncomment "#test1", it'll show :
can't read "element": no such variable
while executing
"expr $sum + $element"
if I uncomment "#test2", it'll show:
can't read "element": no such variable
while executing
"expr $sum + $element"
(procedure "test2" line 5)
invoked from within
"test2"
(file "./test.tcl" line 137)
What I want is of course the test2 behavior. How can I display this error info using catch?