#1 2025-09-11 09:40:14

testgary
Member
Registered: 2025-02-06
Posts: 29

Exception handling

      try
        RestModel.Orm.Add(ORM, 'test');
      except
        // It seems that EngineAdd swallows the exceptions raised by RaiseUtf8, and I can't catch them. I'm not sure if I'm right.
        on E: ESynException do
        ...
      end;  

function TRestStorageMongoDB.EngineAdd(TableModelIndex: integer;
  const SentData: RawUtf8): TID; 

class procedure ESynException.RaiseUtf8(const Format: RawUtf8;
  const Args: array of const);
begin
  raise CreateUtf8(Format, Args);
end; 

The EngineAdd method throws an exception while returning 0. Thus, I was able to catch it.

Last edited by testgary (2025-09-11 09:43:57)

Offline

#2 2025-09-11 19:39:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,181
Website

Re: Exception handling

Yes, this is a documented feature: Add returns 0 and catch exceptions.

You can retrieve the last DB exception message if you need from the mormot.db.core.pas unit.

Offline

Board footer

Powered by FluxBB