| Ticket UUID: | 2935779 | ||
| Title: | Incorrect -errorline from compiled [catch] | ||
| Type: | Bug | Created on: | 2010-01-20 18:57:49 |
| Submitter: | dzach | Assigned to: | dgp |
| Subsystem: | 47. Bytecode Compiler | Severity: | Minor |
| Priority: | 8 | Last modified: | 2014-08-07 09:53:49 |
| Status: | Open | Closed by: | nobody |
| Resolution: | None | Closed on: | |
| Version: | None | ||
| Description: | ||||
The documentation states:
"catch script ?resultVarName? ?optionsVarName?"
... "The value of the -errorline entry is an integer indicating which line of script was being evaluated when the error occurred."
However, if one runs some [catch] code inside a proc, the -errorline integer indicates the line of the proc script that has the error and not the line of the catch script, as is stated in the doc. The following code shows the problem:
proc test {} {
puts inside...\[test]
puts "some more text"
switch {} {
default {
catch {
puts "inside script"
sdfsdf # the error
} err opt
}
}
puts $err
puts $opt
}
% test
inside...[test]
some more text
inside script
invalid command name "sdfsdf"
-code 1 -level 0 -errorcode NONE -errorinfo {invalid command name "sdfsdf"
while executing
"sdfsdf # the error"} -errorline 8
instead of -errorline 3
| ||||
| User Comments: | ||||
dgp added on 2010-01-21 09:15:50:
That's a bug then, not mistaken docs. Please state precisely what release you see this buggy behavior in, and whether or not it is a regression from earlier releases that got things right. dzach added on 2010-01-21 09:27:55:
Release: Tcl8.6b1.1 / Tk8.6b1.1 Same problem with: Tcl8.5a6 / Tk8.5a6 but not with Tcl8.4.16 / Tk8.4.16 since [catch] options were introduced in 8.5 I think. dzach added on 2010-01-21 16:30:55:
I don't call it a bug because I find the functionality correct and as expected, only the docs say it should be different. The way it works now helps pinpoint the error line within the [proc] script, with a simple [info body]. dgp added on 2010-02-18 02:12:39:
Contrast these two:
% proc test {} {
catch {
puts foo
error bar
} m o
puts $o
}
% test
foo
-code 1 -level 0 -errorcode NONE -errorinfo {bar
while executing
"error bar"} -errorline 4
% proc test2 {} {
set catch catch
$catch {
puts foo
error bar
} m o
puts $o
}
% test2
foo
-code 1 -level 0 -errorcode NONE -errorinfo {bar
while executing
"error bar"} -errorline 3
The difference is whether [catch] is compiled,
and when it is, it becomes intstructions within
the larger proc body script which causes
GetSrcInfoForPc() to base its errorLine calculation
off the wrong script start.
Will get back to this one later.
duquette added on 2012-08-25 00:55:12:
I'm seeing this bug in Tcl 8.5.9 on Mac OS X; and it simply isn't a documentation bug. Getting the errorline in the enclosing proc isn't useful. dgp added on 2013-03-20 01:44:35:
miguel, any thoughts on this one? Also, don't we have other commands besides [catch] that compile script bodies into inline bytecodes that would suffer the same problem? msofer added on 2014-08-06 17:06:40:
Nothing much to say on this. dkf added on 2014-08-07 09:53:49:
I think it's been this was since 8.0a1, though you'll have to parse the $::errorInfo to get the line number there. | ||||
