4 ms·
This illustrates how you can use Tcl to ensure that files get closed even when errors happen by combining catch, close and return (from the Tcl manual): pr
by sigzero 11y ago
This illustrates how you can use Tcl to ensure that files get closed even when errors happen by combining catch, close and return (from the Tcl manual):
proc withOpenFile {filename channelVar script} {
upvar 1 $channelVar chan
set chan [open $filename]
catch {
uplevel 1 $script
} result options
close $chan
return -options $options $result
}