我试图理解 Tcl 中的错误和异常。我写了一个小代码如下
proc Div3 {a b} {
return [Div2 $a $b]
}
proc Div2 {a b} {
return [Div $a $b]
}
proc Div {a b} {
if {$b == 0} {
error "Error generated by error" "Info String for error" 401
} else {
return [expr $a/$b]
}
}
if {[catch {puts "Result = [Div3 10 0]"} errmsg]} {
puts "ErrorMsg: $errmsg"
puts "ErrorCode: $errorCode"
puts "ErrorInfo:\n$errorInfo\n"
}
当我使用 运行它时tclsh.exe
,调试器输出如下所示,
% tclsh error-file-1.tcl
ErrorMsg: Error generated by error
ErrorCode: 401
ErrorInfo:
Info String for error
(procedure "Div" line 1)
invoked from within
"Div $a $b"
(procedure "Div2" line 2)
invoked from within
"Div2 $a $b"
(procedure "Div3" line 2)
invoked from within
"Div3 10 0"
但是,当我使用tclsh.exe
通过Komodo IDE运行相同的程序时,我得到的调试器输出如下
ErrorMsg: Error generated by error
ErrorCode: 401
ErrorInfo:
Info String for error
invoked from within
"DbgNub_uplevelCmd 1 $cmd"
invoked from within
"Div $a $b"
invoked from within
"DbgNub_uplevelCmd 1 $cmd"
invoked from within
"Div2 $a $b"
invoked from within
"DbgNub_uplevelCmd 1 $cmd"
invoked from within
"Div3 10 0"
invoked from within
"DbgNub_uplevelCmd 1 $cmd"
invoked from within
"DbgNub_Do 0 {1 17 {249 27}} {puts "Result = [DbgNub_Do 1 {1 17 {265 9}} {Div3 10 0}]"}"
我可以理解来自 Komodo IDE 的调试器输出,tclsh.exe
但无法解释来自Komodo IDE的调试器输出。
特别是,我无法理解DbgNub_Do 0 {1 17 {249 27}} {puts "Result = [DbgNub_Do 1 {1 17 {265 9}} {Div3 10 0}]"}
列表中显示的数字(即{1 17 {249 27}}
)DbgNub_uplevelCmd 1 $cmd
和DbgNub_Do
提前致谢