finally try List1.Free; except end; try List2.Free; except end; end; This code blindly eat exception which does not allow outside code to have an opportunity to handle the exception. Exception should be handled by the code which has the knowledge to handle it.
Regards Leigh www.smootharm.com -----Original Message----- From: Paul Heinz [mailto:[EMAIL PROTECTED] Sent: Friday, 21 July 2006 3:05 p.m. To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List 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
