2017-05-25 81 views
0

您好我是新來的TCL和我試圖運行在一個for循環的命令,而這個命令做的事情需要做,但是,它拋出一個異常,這將導致錯誤循環打破。所以,我需要忽略這個命令產生的任何錯誤,並且每次在我的for循環中仍然嘗試這個命令。嘗試,而忽略我的Tcl命令

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 
} 

請幫我一個很好的解決這個問題

回答

1
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

+0

我已經想通了。是的,使用'catch'可以做到這一點。從我+1。 – vamsi465