Custom exceptions globally


(teo59) #1

Hi,

We have both dataabstract and remote services inside one project and we want to intercept all error messages on one place and raise our custom implementation of exception class. Is that possible for both sdks on single place and how we can achieve that?

What we tray to do is to intercept error messages inside OnWriteException event but without succes as this event is called later in hierarchy. Here is examle:

procedure TServerDataModule.MessageWriteException(Sender: TROMessage; aStream: TStream; E: Exception);
begin
e:=getRaiseErrorMessage(e.Message);
end;

Server is running on Delphi (9.x)


(EvgenyK) #2

you can create descendant from std invoker and override CustomHandleMessage method like

type
  TMyDataService_Invoker = class(TDataService_Invoker)
  protected
    function CustomHandleMessage(const aFactory: IROClassFactory;
      const aMessage: IROMessage;
      const aTransport: IROTransport;
      out oResponseOptions: TROResponseOptions): boolean;  override;
  end;

function TMyDataService_Invoker.CustomHandleMessage(
  const aFactory: IROClassFactory; const aMessage: IROMessage;
  const aTransport: IROTransport;
  out oResponseOptions: TROResponseOptions): boolean;
begin
  try
    result := inherited CustomHandleMessage(aFactory, aMessage, 
                                            aTransport, oResponseOptions);
  except
    on E: Exception do
      raise MyException.Create(getRaiseErrorMessage(e.Message));
   end;
end;

var
  fClassFactory: IROClassFactory;
initialization
  fClassFactory := TROClassFactory.Create('DataService', Create_DataService, 
              TMyDataService_Invoker);
  // RegisterForZeroConf(fClassFactory,'_DataService_rosdk._tcp.');
finalization
  UnRegisterClassFactory(fClassFactory);
  fClassFactory := nil;
end.

(teo59) #3

Nice.
Thanx


(Ivica Lucic) #4

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


(Ivica Lucic) #5

Can I get session in CustomHandleMessages.
I need some session variable


(EvgenyK) #6

you have aMessage.ClientID in CustomHandleMessage so you can get TROSession from SessionManager for this ClientID.