diff options
author | dkf <dkf@noemail.net> | 2004-05-25 20:42:42 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2004-05-25 20:42:42 (GMT) |
commit | 713b40ee99d920c7a84ee0ca8da54d3eac8be9c2 (patch) | |
tree | 61a05640754ba7809dd0a7f58c21f83e6d578623 /doc | |
parent | 90f006c91129f10e9a345a02fe81e7b2ee4d86e4 (diff) | |
download | tcl-713b40ee99d920c7a84ee0ca8da54d3eac8be9c2.zip tcl-713b40ee99d920c7a84ee0ca8da54d3eac8be9c2.tar.gz tcl-713b40ee99d920c7a84ee0ca8da54d3eac8be9c2.tar.bz2 |
Added example
FossilOrigin-Name: bbcd44dae56b22abe510ea9bbcd3078255c29d7e
Diffstat (limited to 'doc')
-rw-r--r-- | doc/close.n | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/doc/close.n b/doc/close.n index c5d772b..d5ba90b 100644 --- a/doc/close.n +++ b/doc/close.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: close.n,v 1.5 2004/04/26 14:38:09 dkf Exp $ +'\" RCS: @(#) $Id: close.n,v 1.6 2004/05/25 20:42:43 dkf Exp $ '\" .so man.macros .TH close n 7.5 Tcl "Tcl Built-In Commands" @@ -62,6 +62,21 @@ The command returns an empty string, and may generate an error if an error occurs while flushing output. If a command in a command pipeline created with \fBopen\fR returns an error, \fBclose\fR generates an error (similar to the \fBexec\fR command.) +.SH EXAMPLE +This illustrates how you can use Tcl to ensure that files get closed +even when errors happen by combining \fBcatch\fR, \fBclose\fR and +\fBreturn\fR: +.CS +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 +} +.CE .SH "SEE ALSO" file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3) |