How catch & log exceptions (Delphi)

I need to intercept all exceptions that occurred on the server (Delphi/FPC) and log it to a file log.

what I am doing now:

procedure TMyService.doSomething;

begin

try

except on E:Exception do begin

Log.DumpExceptionCallStack(E));

raise Exception.Create(E.message);

end;
end;

</code.

Now I want to make it (Log.DumpExceptionCallStack(E)):wink: default for all my service and methods. So, I can easily identify my class and exactly line number that exception occurred …

Some available event on service to catch it ??

Thanks,
Willian

Hello,
Please use TMyService.OnDeactivate event in your service:

procedure TMyService.RORemoteDataModuleDeactivate(const aClientID: TGUID;
  aSession: TROSession);
var
  obj:TObject;
begin
  obj := ExceptObject;
  if (obj is Exception) then
    Log.DumpExceptionCallStack(Exception(obj)));
end;

Thanks worked!