如何获取代码行号和错误信息?

编程入门 行业动态 更新时间:2024-10-27 12:36:19
本文介绍了如何获取代码行号和错误信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 09:14:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1407285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行号   错误信息   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!