[fpc-pascal] Re: Fpc Access Violation if AppConfigDir doesn't exist.

Giuliano Colla giuliano.colla at fastwebnet.it
Mon Feb 11 13:06:54 CET 2013

Il 11/02/2013 12:35, Michael Van Canneyt ha scritto:
> On Mon, 11 Feb 2013, Giuliano Colla wrote:
>> Il 11/02/2013 09:21, Michael Van Canneyt ha scritto:
>>> 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
>> This is true only if you invoke the program from command line, which 
>> is something the end user will never do.
> That is not the problem of TIniFile, but of the application programmer.
> TIniFile properly reports any error, as it should, with an exception.
> It is always up to the application programmer to deal with such cases.
> That this is sometimes tricky in a GUI application, cannot be helped.

It can be helped both by reducing the likelihood of the event, as you've 
done, and by not suggesting to use in that case a try..finally construct 
in a GUI application, which would mask the errors.
This suggestion comes historically from Delphi literature, but 
fpc/Lazarus developers should never forget that they're smarter than 
Delphi people. ;-)


More information about the fpc-pascal mailing list