[fpc-pascal] Second AV is not catched

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Jan 20 00:22:53 CET 2005


The below program has 2 try..except blocks. In each block an object is
created, that gives an access violation.
The first is catched, the second not. 
Why?


program ConstructorKill;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils; 

type
  { TMyObject }

  TMyObject = class(TObject)
  public
    constructor Create(TheOwner: TObject);
  end;

{ TMyObject }

constructor TMyObject.Create(TheOwner: TObject);
begin
  // create AV
  if TheOwner.ClassName='' then;
end;

begin
  writeln('Creating the first time');
  try
    TMyObject.Create(nil);
  except
    on E: Exception do begin
      writeln('E='+E.Message);
    end;
  end;
  writeln('Creating the second time');
  try
    TMyObject.Create(nil);
  except
    on E: Exception do begin
      writeln('E='+E.Message);
    end;
  end;
  writeln('Ending ..');
end.


Mattias




More information about the fpc-pascal mailing list