[Lazarus] exception handling in constructor

Xiangrong Fang xrfang at gmail.com
Sat Mar 2 03:49:30 CET 2013


Hi there,

If my class constructor looks like this:

constructor TMyClass.Create(fn: string);
begin
  sl := TStringList.Create;
  try
    fs := TFileStream.Create(fn, fmOpenRead);
  except
    self.Destroy;
  end;
end;

I create the objec like:  MyInstance :=
TMyClass.Create('AnNonExistentFile');  An exception occured, I can ensure
that:

   1. there is no memory leak.
   2. the MyInstance variable is assigned *nil*?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130302/d25feaa8/attachment-0002.html>


More information about the Lazarus mailing list