[odb-users] Questions on object_not_persistent exception

Boris Kolpackov boris at codesynthesis.com
Tue Oct 31 07:31:01 EDT 2023


Reilly He <reillyhekazusa at gmail.com> writes:

> We recently encountered the '*object_not_persistent*' exceptions when using
> odb.
>
> [...]
> 
> Based on the manual, the exception itself looks like this:
> 
> > struct object_not_persistent: exception {
> >
> > virtual const char*
> >
> > what () const throw (); };
> >
> 
> We still find it not enough to quickly detect who triggers the exception.

Generally, ODB exceptions are derived from the underlying database error
code/message and the amount of information you get varies. Unfortunately,
for SQLite (which is the database I assume you are using), this is just
the high-level error code without any specifics (like the table name or
primary key value) that would allow you to map this back to your objects.


> Do you know how to get more information when this exception happens? *Like
> the id, or the operation (R/U/D), or even the type of the Model?*

A couple of things come to mind:

1. Don't catch the exception and instead let the application crash under
   the debugger (or examine the core). This should give you the exact
   location of where the exception was thrown and from outer stack frames
   you should be able to determine the object type and object id.

2. Enable SQL statement tracing:

   https://www.codesynthesis.com/products/odb/doc/manual.xhtml#3.13

   Provided your application is single-threaded (or you make arrangements
   for saving traces on the per-thread basis), the last statement
   executed should give you the idea of the object(s) involved. Note that
   because prepared statements are used, you won't see the object id
   in these traces, only the parameter placeholders.

3. For client-server databases (so not SQLite), there is also the option
   of looking into server logs to see which SQL statements get executed.
   There you may be able to  see both the statement and the values for
   the parameters.



More information about the odb-users mailing list