On Mon, 11 Feb 2013, Giuliano Colla wrote:
3) But if also the *path* to the file doesn't yet exist, it just crashes
without rising an exception that the user application can handle somehow.
This is incorrect. It does tell you why it fails.
This is rather unpleasant, because the path provided by GetAppConfigXx does
usually exist, so you have an application which 99% of the times works just
fine, and 1% of the times crashes without telling why.
It tells you *exactly* why it 'crashes':
home: >./ti
An unhandled exception occurred at $000000000042AE87:
EFCreateError: Unable to create file "/tmp/path/to/nothing.txt"
$000000000042AE87
home: >cat ti.pp
program ti;
uses inifiles;
begin
with TMemIniFile.create('/tmp/path/to/nothing.txt') do
try
WriteString('A','B','C');
UpdateFile;
finally
Free;
end;
end.
However, I agree that it should try to create the path as well.
I have adapted the implementation.
You'll get an error telling you if it failed to create the dir:
An unhandled exception occurred at $0000000000427F7E:
EInOutError: Could not create directory "/my/path/to/"
$0000000000427F7E
Which means that you are still (as previously) responsible for catching
possible errors.
But these errors should be less frequent with this change.
Michael.
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal