Title: Message
Basically correct.
An  exception is/can be any old object. The only difference is that if an object is used in a raise statement, then that object is then lifetime managed by the exception handlers. 
 
The only issue with this, is that if a another exception is raised in an except block while handling the first exception, then the first exception is lost and never destroyed  - this was the case last time I looked into this particular issue/leak.
 
Myles.
-----Original Message-----
From: Allan, Samuel [mailto:[EMAIL PROTECTED]
Sent: Friday, 14 November 2003 16:30
To: Multiple recipients of list delphi
Subject: [DUG]: Freeing exceptions?

Exception decends from TObject. Correct me if I am wrong, but if I create an exception and do not raise it, I then have to free it? But if I create an exception, muck about with it, and then raise it I do not have to free it?
 
 
 
Is the below code a memory leak?
 
procedure TSam.Samuel;
var
  e: Exception;
begin
  e := Exception.Create('Foobar');
end;
 
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;

Reply via email to