Yeah, straight after replying with why I wanted to know, it occurred to
me that the same effect was still possible without creating an exception
object. But it is also good to know one more little thing about how
everything works. So thanks.

-----Original Message-----
From: Dennis Chuah [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 17 2003 12:53 p.m.
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Freeing exceptions?


Message> Is the below code a memory leak?

> procedure TSam.Samuel;
> var
>   e: Exception;
> begin
>   e := Exception.Create('Foobar');
> end;

Yes, every time the method is called.

> Is the below code okay?

> procedure TSam.TrySamuel;
> var
>   e: Exception;
> begin
>   e := Exception.Create('Foobar');
>   try
>     //do some stuff
>   finally
>     e.Free;
>   end;
> end;

Okay is subjective.  From a pure coding point of view, as long as "e" is
not used to raise any exceptions inside the try -- finally, the code is
OK. From a design point of view, it is IMHO, poor practise to create an
exception object and not raise it.  A class should do only one thing and
do it well.  So an exception class should only be used to raise
exceptions, and no more.  Create it when you need to use it.

Dennis.
------------------------------------------------------------------------
---
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to