Giuliano Colla wrote:
Il 11/02/2013 12:40, Mark Morgan Lloyd ha scritto:
Giuliano Colla wrote:
However, what I've learned from this episode is that while attempting
to save configuration data using TINIFile on program termination you
should never use a try..finally construct, as it's suggested
everywhere, but rather a try..except (or both). Otherwise you'll
never be able to catch possible errors.
I'd suggest that there are two separate cases here. In the first case,
near the start of a program you decide whether there is a preexisting
.ini file, create it if not, and if necessary update it to contain
e.g. the default name of a backend server. In the second case, at the
the end of a program run you save the current session's state.
I was speaking of the second case(saving configuration data to your .ini
file).
When attempting to load configuration data, a try..finally is ok. If no
configuration data are available you already have a built-in mechanism
to provide default values.
But when attempting to save the current session's state at the end of
the program, a try..finally will mask any error, and possibly lead to an
unpleasant lock up.
But you should have already ascertained early in the program- when the
.ini was created (possibly from a template) or read- that the path etc.
was accessible. What's more you're typically doing this before the main
program logic is started, so you shouldn't get caught by finalization
that's only there to clear up after the main program.
So this is, basically, bad application coding.
Besides which, while I agree that your original point
> It turned out that the reason was simply that the default
> AppConfigDir (~/.config/ ) wasn't there, and therefore in the
> two usual lines
illustrates something that is inconvenient, my understanding is that
different distreaux (not to mention the preference of different system
owners) use ~/.config to a varying extent. If anything, it is the fault
of AppConfigDir for indicating a directory without raising an exception
pointing out that it doesn't yet exist :-)
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal