【问题标题】:Skipping error message while using tcl for loop for creating multiple components使用 tcl for 循环创建多个组件时跳过错误消息
【发布时间】:2021-08-06 05:29:32
【问题描述】:

我是 TCL 的新手。对不起,简单的问题。我想使用 TCL 创建实体。

如果我的范围内有任何组件,我想跳过它并向前增加 1 步。

例如,我创建了 comp pshell.15,此代码工作到 15 并退出并出现错误。

请帮我跳过这个错误。

问候


for {set i 10} {$i <20} {incr i} {

 *createentity comps name=pshell.$i id=$i
 puts $i
            if { [catch {*?????? }] } {
                incr i 
                continue
                

}
}

【问题讨论】:

  • 您输入的字符是*,还是试图突出显示内容? (代码荧光笔根本不尊重它们。)我问是因为它不是命令名称中的常见字符。还有……错误信息是什么意思?Tcl 的错误信息通常非常善于描述眼前的问题。

标签: error-handling try-catch tcl


【解决方案1】:

一般来说,假设*createentity comps name=pshell.$i id=$i 命令是正确的(不管它是什么,我真的不知道!),在失败的情况下跳过错误消息你应该使用try。但是,这不会跳过命令,这只是让您可以优雅地处理它。

incr i 之前不需要continue

for {set i 10} {$i < 20} {incr i} {
  try {
    *createentity comps name=pshell.$i id=$i
  } on error {} {
    continue
  }
  puts $i
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 2013-01-22
    • 2021-12-01
    • 2022-01-01
    相关资源
    最近更新 更多