Agreed. The idea that an object raises an exception in its destructor is mind boggling.

----- Original Message ----- From: "Paul Heinz" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "NZ Borland Developers Group - Delphi List" <[email protected]>
Sent: Friday, July 21, 2006 3:04 PM
Subject: RE: [DUG] Related try..finally question


Leigh wrote:

I think should use FreeAndNil like the one below. The reason for that is
maybe after finally there is some code try to access List1/List2, without
set to nil, it would be extremely hard to detect this sorts of bug(Once
free, try to access). Set to nil is not a big performance downgrade after
now Intel release core 2 duo cpu. ;-) I am considering to buy one
core 2 duo
cpu.;-)

  List1 := Nil;
  List2 := Nil;
  try
    List1 := TList.Create;
    List2 := TList.Create;

  finally
    FreeAndNil(List1);
    FreeAndNil(List2);
  end;

FreeAndNil is all good for the reason you cite and I recommend it too, but
it doesn't resolve the issue Dennis is defending against. Namely that if
List1.Free causes an exception, List2.Free is never executed since Delphi
(well, Windows SEH infrastructure really) will exit this finally block
immediatelty and chain up to the next exception or finally handler in the
excepion frame chain.

TTFN,
 Paul.





_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi



--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 14/07/2006





--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 14/07/2006

_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to