如何获取代码行号和错误信息? [英] How can I get the code line number along with errorinfo?

查看:29
本文介绍了如何获取代码行号和错误信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆