Einzelnen Beitrag anzeigen

jottkaerr

Registriert seit: 2. Jul 2007
Ort: Tuttlingen
81 Beiträge
 
Delphi 10.1 Berlin Professional
 
#2

Re: Exception in Basis-Klasse abfangen?

  Alt 13. Feb 2008, 06:09
Hallo,

mach das ganze mit dem Template-Muster:

Delphi-Quellcode:
type
  TBase = class(TObject)
  protected
    procedure DoThis; virtual;
    procedure DoThat; virtual;
  public
    procedure Work;
  end;

  TDerived = class(TBase)
  protected
    procedure DoThis; override;
    procedure DoThat; override;
  end;

{ TBase }

procedure TBase.DoThis;
begin
  { ... }
end;

procedure TBase.DoThat;
begin
  { ... }
end;

procedure TBase.Work;
begin
  try
    DoThis;
    DoThat;
  except
    on e: Exception do
      { Exceptions behandeln }
  end;
end;

{ TDerived }

procedure TDerived.DoThis;
begin
  { ... }
  if Error then
    raise Exception.Create('Fehle in TDerivedDoThis!');
  { ... }
end;

procedure TDerived.DoThat;
begin
  { ... }
  if Error then
    raise Exception.Create('Fehle in TDerivedDoThat!');
  { ... }
end;
jkr
Jürgen Krämer
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
  Mit Zitat antworten Zitat