Sujet : Re: How to close a file if successfully opened
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.tclDate : 21. Jun 2024, 10:47:21
Autres entêtes
Message-ID : <RJ-dna0mWOe00ej7nZ2dnZfqnPUAAAAA@brightview.co.uk>
References : 1 2
User-Agent : Pan/0.154 (Izium; 517acf4)
I tried using both trap and finally but it didn't work.
Having seen your code quotes I realise that I made a mistake with the
syntax, so here's what I used in the end:
try {
set fh [::ini::open $::config::filename -encoding utf-8 r]
set ::config::geometry \
[::ini::value $fh Window geometry [wm geometry .]]
tk scaling [::ini::value $fh Window scale [tk scaling]]
ttk::style theme use \
[::ini::value $fh Window theme [ttk::style theme use]]
set ::config::tab [::ini::value $fh Window tab]
} trap {POSIX ENOENT} {} {
;# do nothing and rely on defaults
} finally {
if {[info exists fh] && $fh ne ""} {
::ini::close $fh
}
}
I'd gone wrong in the trap; I'd forgotten the second set of braces.
Thank you.