gpt4 book ai didi

error-handling - 如何找出 tcl 命令可能生成哪些错误?

转载 作者:行者123 更新时间:2023-12-03 07:39:56 32 4
gpt4 key购买 nike

tcl try manpage ,它有以下示例:

try {
set f [open /some/file/name w]
} trap {POSIX EISDIR} {} {
puts "failed to open /some/file/name: it's a directory"
} trap {POSIX ENOENT} {} {
puts "failed to open /some/file/name: it doesn't exist"
}

那太好了,它有效,但是我如何发现 {POSIX ENOENT}open 的可能陷阱模式? open manpage没有提到它。对于tcl中给定的任意命令,如何找出可能的错误是什么?

最佳答案

try {} trap {} 用于当存在需要捕获的特定错误时。对于更一般的陷阱,请使用try {} on error {}

try {
set fh [open myfile.txt w]
} on error {err res} {
puts "Error on open: $res"
}

还有catch命令:

if { [catch {set fh [open myfile.txt w]}] } {
puts "error on open."
}

引用文献:try catch

关于error-handling - 如何找出 tcl 命令可能生成哪些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54247244/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com