Exception handling

I’m trying to understand exactly how exceptions are handled by the server.

It appears that, if an exception is raised during a service call from a client, then that exception is caught by the server and then forwarded back to the client which re-raises it, so the user sees a message telling them that an exception was raised on the server.

Where is this exception handling and can I hook it in any way? What I want is to trap exceptions on the server and log the details to the Windows event log together with diagnostic information such as a stack trace. Whilst I’m not interested in certain exceptions such as business processor validation errors (where it’s sufficient to just inform the user), I want to trap genuinely unexpected exceptions on the server and log the details.

Also, what happens if there is no client involved, i.e. the server is making use of it’s own services internally? In such cases, surely any exceptions raised will just be eaten by the framework and I’ll never see them?

If anyone can shed some light on this for me I’d appreciate it.

You can use TROMessage.OnWriteException event and detect EROServerException and others exceptions here.

you can catch exceptions in standard manner, i.e.:

  lserver := TMyServer.Create(nil);
  try
     try  
       lserver.MyMethod;
     except
       on E: Exception do
          ...
     end;
  finally
    lServer.Free;
  end;

Thanks, I actually found this article:

http://talk.remobjects.com/t/globally-handle-server-side-exceptions

And ended up using that system to hook at the lowest level possible which seems to work. I had to override TApplicationService.DoHandleException to stop the default event logging as I’m doing my own logging with full stack trace info.