Tl; Dr: it is not implemented in an applicable way (in 10.1 Berlin).
I ran into the same problem, and after reading a large number of sources, I did not find a practical solution.
So, an exemplary (mine) StackTrace would look like this:
MyClass::MyServerMethod() System::Rtti::TRttiMethod::Invoke Dsreflect::TDSMethod::Invoke(TObject, TDSMethodValues) TDSServerConnectionHandler::DbxExecute(const TDBXExecuteMessage) TDSServerCommand::DerivedExecuteUpdate TExecuteCallback TDSService::Execute(const string, const TRequestCommandHandler, TExecuteCallback) TDSService::ProcessRequest(const string, const TRequestCommandHandler, TExecuteCallback) TDSRESTService::ProcessREST(const string, const string, const TArray<Byte>, const TRequestCommandHandler) TDSRESTService::ProcessGETRequest(const string, TStrings, TArray<Byte>, TRequestCommandHandler) TDSRESTServer::DoDSRESTCommand(TDSHTTPRequest, TDSHTTPResponse, string) TDSRESTServer::DoCommand(TDSHTTPContext, TDSHTTPRequest, TDSHTTPResponse) Dshttpwebbroker::TDSRESTWebDispatcher::DispatchRequest(TObject, Web::Httpapp::TWebRequest, Web::Httpapp::TWebResponse)
Note. It is completely dependent on the use of DataSnap. In the above cases, requests are sent to the DataSnap API via TDSRESTWebDispatcher (starting with TIdCustomHTTPServer ).
- Each
Exception raised in ServerMethod will fall into TDSService::ProcessRequest . - In this procedure, every
Exception caught, and ONLY its Message appended to TRequestCommandHandler->CommandList . - Further down,
Message written as a JSON / DBX command to exit.
Therefore, we will never be able to handle the Exception object and access StackTrace or other information. Thus, this in itself is unacceptable and should change
The good news is that this procedure is virtual and can be overwritten. The bad news is that in the above example, you need to extend the TDSRESTService with your own ProcessRequest procedure (including your error handler), TDSRESTServer with your own DoDSRESTCommand (where the TDSRESTService is created into a monstrously large procedure) and TDSRESTWebDispatcher (depending on your use) .
My personal recommendation is not to use DataSnap.
Note. At the time of writing this question, I did not find any call to the OnError event.