This is how -errorinfo looks when I call [foo] directly:
my error
while executing
"throw AAA "my error""
(procedure "bar" line 2)
invoked from within
"bar"
(procedure "foo" line 2)
invoked from within
"foo"
("try" body line 3)
nice and clean - this is what I want to achieve with [duration]
Let's try to handle the error:
proc duration {script varName} {
upvar 1 $varName elapsed
set now [clock millis]
if {[catch {uplevel 1 $script} result errOpts]} {
dict incr errOpts -level ;# makes no difference, but I did my due diligence
return -options $errOpts $result
}
set elapsed [expr {[clock millis] - $now}]
}
resulting -errorinfo:
my error
while executing
"throw AAA "my error""
(procedure "bar" line 2)
invoked from within
"bar"
(procedure "foo" line 2)
invoked from within
"foo"
("uplevel" body line 2)
invoked from within
"uplevel 1 $script"
invoked from within
"duration {
foo
} elapsed"
("try" body line 2)
P.S. is it possible to format Tcl code somehow here? it becomes really unreadable after posting :(