Exceptions in Constructors and Destructors

Check out Alister Christie’s latest movie on CodeGearGuru.com. He covers the elusive Exceptions in Constructors and Destructors. Thanks Alister. That was one of the questions from my Exceptional Exceptions session that I needed to follow up on.

Tags: , , ,

2 Responses to “Exceptions in Constructors and Destructors”

  1. Mitja Says:

    There is one more way of doing it (if assuming that destructors do not raise exceptions):
    var S1,S2:TSomeObject;
    begin
    S2:=nil;
    S1:=TSomeObject.Create;
    try
    // Some Code 1
    S2:=TSomeObject.Create;
    // Some Code 2
    finally
    S1.Free;
    S2.Free;
    end;

  2. Alister Christie Says:

    Thanks for the mention ;-). I made this video because of a discussion I had with another Delphi community member about some of the lazy exception handling I’ve done in some of my other videos, I was kind of hoping that this one would make up for it.

Leave a Reply