Tk Library Source Code

View Ticket
Login
Ticket UUID: 1225868
Title: try command
Type: RFE Version: None
Submitter: dkf Created on: 2005-06-22 21:31:07
Subsystem: control Assigned To: dgp
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-10-09 00:48:20
Resolution: Closed By: dgp
    Closed on: 2009-10-08 17:48:20
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
}
User Comments: dgp added on 2009-10-09 00:48:20:

allow_comments - 1