| Description: |
Here's a [try] command using the features of TIP#90,
perhaps for adding to the control package. I'm
perfectly happy with the code being published under the
normal tcllib license.
proc try {script args} {
upvar 1 try___msg msg try___opts opts
if {[llength $args]!=0 && [llength $args]!=2} {
return -code error "wrong \# args: should be \"try
script ?finally script?\""
}
if {[llength $args] == 2} {
if {[lindex $args 0] ne "finally"} {
return -code error "mis-spelt \"finally\" keyword"
}
}
set code [uplevel 1 [list catch $script try___msg
try___opts]]
if {[llength $args] == 2} {
uplevel 1 [lindex $args 1]
}
if {$code} {
dict incr opts -level 1
return -options $opts $msg
}
return $msg
}
|