Error handling 尝试并忽略我的tcl命令中的错误

Error handling 尝试并忽略我的tcl命令中的错误,error-handling,try-catch,tcl,Error Handling,Try Catch,Tcl,您好,我是tcl新手,我正在尝试在for循环中运行一个命令,而这个命令执行它需要执行的操作,但是,它抛出一个异常,导致循环中断。因此,我需要忽略该命令产生的任何错误,并在for循环中每次都尝试该命令 for loop { #do some stuff $chassis exportPacketTrace $new_name -compress false 1 2 both #try this but ignore its error and continue #do so

您好,我是tcl新手,我正在尝试在for循环中运行一个命令,而这个命令执行它需要执行的操作,但是,它抛出一个异常,导致循环中断。因此,我需要忽略该命令产生的任何错误,并在for循环中每次都尝试该命令

for loop {
    #do some stuff
    $chassis exportPacketTrace $new_name -compress false 1 2 both #try this but ignore its error and continue
    #do some stuff
}
请帮我解决这个问题

if {[catch {$chassis exportPacketTrace $new_name -compress false 1 2 both} issue]} {
    puts "There is a failure and it is ignored"
    puts "Reason for failure : $issue"
}
参考资料:


参考资料:

我已经弄明白了。是的,使用“catch”就可以了+我已经猜出来了。是的,使用“catch”就可以了+从我这里得到1。