From the Redundant Department of Redundancy...

From the Redundant Department of Redundancy...

    if (_List = nil) then
    begin
      try
        _List := TStringList.Create;
      except
        _List.Free;
      end;
    end;

Never mind the fact that the code references _List immediately afterwards without checking if _List is nil or not...

Comments

  1. Trying to trap a failed TStringList.Create is like grasping at straws. When it happens, the only sane thing to do is call Halt() and pray that no permanent data got corrupted ;-)

    ReplyDelete
  2. Either that or someone really doesn't trust the RTL code :-P

    ReplyDelete
  3. and even a _List.Free won't set _List to nil. Wasn't there a procedure doing such a thing?

    ReplyDelete
  4. Eric Grange Yeah, that's pretty much the definition of a catastrofic failure in 99% of the cases.

    Paul Foster Seems to have some serious trust issues indeed ;)

    ReplyDelete
  5. Uwe Raabe Shhh, it shall remain nameless, for it is the anti-christ. At least that's what I've heard on the Borland/CodeGear/EMB forums...

    ReplyDelete
  6. I've lately been seeing some code like that.....

    ReplyDelete
  7. Why _List.Free is not protected?  :)

    ReplyDelete
  8. _List is a local variable? or a global variable?

    If a global, ok, test it.
    If not its redundant.

    Use finally  before ".free".

    ReplyDelete
  9. Dan Sohad It's a private class member. However the try/except is completely redundant regardless.

    ReplyDelete
  10. maybe not: if not have"free memory"? ;)
    hummm
    now i understand...
    I thought was another parts omited in this code. 
    It's a joke!
    Sorry.

    ReplyDelete

Post a Comment