Reputation: 10979
#!/usr/bin/tclsh
proc test {} {
aaa
}
test
When I run this script I get error message:
invalid command name "aaa"
while executing
"aaa"
(procedure "test" line 2)
invoked from within
"test"
(file "./a.tcl" line 7)
If I run test command in catch
I get only first line of error message.
#!/usr/bin/tclsh
proc test {} {
aaa
}
catch test msg
puts $msg
This prints:
invalid command name "aaa"
Is it possible to get full error message (file, line, procedure) in catch command? My program has many files and by getting just one line of error message it is difficult to find from where is it.
Upvotes: 1
Views: 1310
Reputation: 33223
The short answer is to look at the value of errorInfo
which will contain the stack trace.
The more complete answer is to look at the catch and the return manual pages and make use of the -optionsVarName
parameter to the catch
statement to collect the more detailed information provided. The return
manual page gives some information on using this. But a rough example from an interactive session:
% proc a {} { catch {funky} err detail; return $detail }
% a
-code 1 -level 0 -errorstack {INNER {invokeStk1 funky} CALL a} -errorcode NONE -errorinfo {invalid command name "funky"
while executing
"funky"} -errorline 1
%
The detail
variable is a dictionary, so use dict get $detail -errorinfo
to get that particular item.
Upvotes: 3