问题描述
限时送ChatGPT账号..我正在使用以下 TCL 代码:
I am using the following TCL code:
proc RunCSM { scen } {
catch { $scen start }
if { "[$scen status]" != "SUCCESS" } {
puts "$scen FAILED. Error Info:"
puts "[$scen errorInfo]" ...
问题是,在这种情况下,有错误,它显示错误信息调试信息作为errorInfo标志的输出,但在这种情况下,我还需要失败代码的行号.这怎么可能?
The problem is that in this case that there is an error, it shows the error info debug information as desired as the output of errorInfo flag, but in this case I need also the line number of the code that fails. How is this possible?
推荐答案
从 8.5 开始,最简单的方法是切换到 catch
的形式,让你可以将扩展的结果信息作为字典(在下面的 opt
变量中)在脚本之后的 second 可选参数中:
The easiest way, from 8.5 onwards, is to switch to the form of catch
that lets you get the extended result information as a dictionary (in the opt
variable below) in its second optional argument after the script:
catch { $scen start } msg opt
if { "[$scen status]" ne "SUCCESS" } { # use 'ne' to compare strings, please
set info [dict get $opt -errorinfo]
set line [dict get $opt -errorline]
puts "$scen FAILED saying '$msg' at $line. Error Info:"
puts $info
# ...
}
这篇关于如何获取代码行号和错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论