Try...Finally question

From: Eddy Fontaine (eddy.remove.fontaine_at_pandora.remove.be)
Date: 01/05/05


Date: Wed, 5 Jan 2005 18:13:32 +0100

Hi,
I am trying to avoid exception during file I/O by
using a try finally statement.

To avoid 'memory leak', i want to be sure that the file
will be closed, if it has been open by the program.

Should i write:

.
.
AssignFile(F,"MyFile.txt);
Reset(F);
Try
    WriteLn(F,"This is my string");
Finally
    CloseFile(F);
End;
.
Or should i write :

.
Try
    AssignFile(F,"MyFile.txt);
    Reset(F);
    WriteLn(F,"This is my string");
Finally
    CloseFile(F);
End;
.
.
In fact, wich is the statement that could cause an exception ?
Thanks for your help !

Eddy.



Relevant Pages

  • Re: Try...Finally question
    ... > I am trying to avoid exception during file I/O by ... > To avoid 'memory leak', i want to be sure that the file ... An alternate construction would be to wrap the Reset ...
    (comp.lang.pascal.delphi.misc)
  • Re: Try...Finally question
    ... Eddy Fontaine wrote: ... > I am trying to avoid exception during file I/O by ... > To avoid 'memory leak', i want to be sure that the file ...
    (comp.lang.pascal.delphi.misc)