"Barry Kelly" <✉eircom.net> wrote
end;
end;
{ interface & implementation }
interface
type
IException = interface ['{3125F638-5ADE-4EFB-A580-4EE129F7D840}']
function E : Exception;
function Ok : Boolean;
function GetHandled : Boolean;
procedure SetHandled(Handled : Boolean);
property Handled : Boolean read GetHandled write SetHandled;
end;
TException = class(TInterfacedObject, IException)
private
FException : Exception;
FHandled : Boolean;
public
constructor Create(E : Exception);
procedure FreeInstance; override;
function GetHandled : Boolean;
procedure SetHandled(Handled : Boolean);
function E : Exception;
function Ok : Boolean;
end;
TNoException = class(TException)
public
constructor Create;
end;
function Ok : IException;
implementation
var
SOk : IException;
function Ok : IException;
begin
if not assigned(SOk) then
SOk := TNoException.Create;
Result := SOk;
end;
{ TException }
constructor TException.Create(E: Exception);
begin
inherited Create;
FException := E;
end;
function TException.E: Exception;
begin
Result := FException;
end;
procedure TException.FreeInstance;
var
Handled : Boolean;
E : Exception;
begin
Handled := FHandled;
E := FException;
try
inherited;
except
E.Free;
raise;
end;
if Handled then
E.Free
else
raise E;
end;
function TException.GetHandled: Boolean;
begin
Result := FHandled
end;
function TException.Ok: Boolean;
begin
Result := Self is TNoException
end;
procedure TException.SetHandled(Handled: Boolean);
begin
FHandled := Handled
end;
{ TNoException }
constructor TNoException.Create;
begin
inherited Create(Exception.Create(''));
SetHandled(true);
end;