title: Delphi raise exception in constructor
body: <p><strong>SITUATION</strong></p>
  
  <p>I am going to write a class and the constructor is a custom one that I have made because I need to initialize some values. This is the code I've written so far:</p>
  
  <pre><code>type
   TCombinatorio = class(TObject)
    private
     valN, valK: integer;
     result: double;
    public
     property K: integer read valK;
     property N: integer read valN;
     constructor Create(valN: integer; valK: integer);
   end;
  
  constructor TCombinatorio.Create(valN: Integer; valK: Integer);
  begin
    inherited Create;
     Self.valN := valN;
     Self.valK := valK;
  
    if ((valN &lt; 0) or (valK &lt; 0)) then
     begin
      raise Exception.Create('N and K must be &gt;= 0');
     end;
  
  end;
  </code></pre>
  
  <p>Since I am going to do some math calculations, I need to avoid negative numbers.</p>
  
  <hr>
  
  <p><strong>QUESTION</strong></p>
  
  <p>Can I raise an exception in the constructor in that way? I am running the code in this way:</p>
  
  <pre><code>procedure TForm1.Button1Click(Sender: TObject);
  var a: TCombinatorio; 
      b: string;   
  begin
  
   a := TCombinatorio.Create(5,-2);
  
   try
    //some code
   finally
    a.Free; 
   end;
  
  end;
  </code></pre>
  
  <p>As you can see here I have wrong parameters for my constructor, since the second is negative. I also cannot understand (according with the code of my constructor) if the <code>a.Free</code> inside the finally is really needed because when the constructor raises the exception, the destructor is called.</p>
  
  <p>I thought to include the <code>a := TCombinatorio.Create(5,-2);</code> inside the try-finally block to avoid the problem but I am not sure. What do you think?</p>