title: Using exception mechanism instead of "if" to treat a default object parameter in Delphi
body: <p>Please, look the following excerpt of code:</p>
  
  <pre><code>TCustomPoint = class
    private
      //many other fields
      mPoint: TPoint;
    public
      //many other stuff: constructor, destructor, methods, etc.
      function ToPoint(Axis: TAxis = nil);  
  end;
  </code></pre>
  
  <p>In the <code>ToPoint</code> implementation I want to do something if an Axis object was passed and a different thing if  it wasn't. So the obvious implementation would be:</p>
  
  <pre><code>function TCustomPoint.ToPoint(Axis: TAxis = nil): TPoint;
  begin
    if Assigned(Axis) then
      Result:=Axis.Reallocate(Self.mPoint);
    else
      Result:=Self.mPoint;
  end;
  </code></pre>
  
  <p>but this method will be called over thousands of <code>TCustomPoint</code> objects where sometimes an Axis will be passed so I am wondering if I would improve a bit the performance using the exception mechanism instead of <code>if</code>. Something like this:</p>
  
  <pre><code>function TCustomPoint.ToPoint(Axis: TAxis = nil): TPoint;
  begin
    try
      Result:=Axis.Reallocate(Self.mPoint);
    except on
      E: EAccessViolation do Result:=Self.mPoint;
  end;
  </code></pre>
  
  <p>Look that I just catch an <code>EAccessViolation</code> exception so if there was any other type of exception it won't be manage by me so it would be raised as expected. In this example, the only way an <code>EAccessViolation</code> exception occur would be accessing the empty Axis object. <strong>Is that correct? Does the second implementation really improve something? Is there any cons?</strong></p>