texception10.pp 734 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {$ifdef fpc}{$mode objfpc}{$H+}{$endif}
  2. uses
  3. Classes, SysUtils;
  4. type
  5. { TMyObject }
  6. TMyObject = class(TObject)
  7. public
  8. constructor Create(TheOwner: TObject);
  9. end;
  10. { TMyObject }
  11. constructor TMyObject.Create(TheOwner: TObject);
  12. begin
  13. // create AV
  14. if TheOwner.ClassName='' then;
  15. end;
  16. var
  17. i : integer;
  18. begin
  19. i:=0;
  20. writeln('Creating the first time');
  21. try
  22. TMyObject.Create(nil);
  23. except
  24. on E: Exception do begin
  25. writeln('E='+E.Message);
  26. inc(i);
  27. end;
  28. end;
  29. writeln('Creating the second time');
  30. try
  31. TMyObject.Create(nil);
  32. except
  33. on E: Exception do begin
  34. writeln('E='+E.Message);
  35. inc(i);
  36. end;
  37. end;
  38. writeln('Ending ..');
  39. if i<>2 then
  40. halt(1);
  41. end.