【发布时间】:2020-05-09 23:05:56
【问题描述】:
假设我在try/trap/finally 中包含以下glob 命令:
proc generateSubmissionFolder {cover_letter_resume submission_path} {
set submission_parent [file dirname $submission_path]
set latest_submission_folder [lindex [lsort [glob -directory $submission_parent -type d *]] end]
set latest_submission_file [lindex [glob -directory $latest_submission_folder *[file extension $cover_letter_resume]] end]
createSubmissionFolder $latest_submission_file $submission_path
}
proc createSubmissionFolder {source destination} {
puts "Creating $destination folder."
file mkdir $destination
puts "Copying $source to $destination"
file copy $source $destination
}
try {
# I gathered user input and stored them in the variables $company_name and $position.
set submission_path [file join $company_name $position $yearmonthday]
if {[file exists [file dirname $submission_path]]} {
generateSubmissionFolder $coverletterresume $submission_path
} else {
createSubmissionFolder $coverletterresume $submission_path
}
} trap {Value Empty} {errormessage} {
puts "$errormessage"
} finally {
puts "$argv0 exiting."
}
如果没有找到文件夹,我想提供一个人类可读的错误消息,但我不确定要捕获什么错误。根据answer我之前的问题:
Tcl 没有预定义的异常层次结构。
我尝试的唯一解决方法是使用-nocomplain 开关,然后检查latest_submission_folder 是否为空白。
有没有办法捕获FileNotFound 或FolderNotFound 错误?
【问题讨论】: