[odb-users] Creation of ODB cache

Boris Kolpackov boris at codesynthesis.com
Thu May 31 14:54:39 EDT 2012


Hi Davide,

Davide Anastasia <Davide.Anastasia at qualitycapital.com> writes:

> Could you derive the exceptions for each class as derivation of
> object_not_persistent?
> In this way, you can either give the possibility to catch a
> class-dependent exception, or a more general one.

Yes, we could certainly do that. The problem, as I mentioned
earlier, is code bloat. With each per-object exception comes a
virtual function table, type information, destructor, what(),
etc, etc. Seeing that this functionality is probably not needed
by every applications (you are the first person asking for
something like this), I am not sure this is a good idea.

That's also the reason why I was thinking about std::type_info --
it is a much lighter-weight approach, if quite a bit less
convenient to use.  


> So my current aim is to provide a sensible error message in the
> response message, so the user can quickly spot the error and fix
> that.

With the type_info approach you will easily be able to find which
object triggered the exception with code along these lines:

try
{
  ...
}
catch (const std::object_not_persistent& e)
{
  std::type_info& ti (e.class_info ());

  if (ti == typeid (object1))
  {
  }
  else if (ti == typeid (object2))
  {
  }
}

It is not as elegant as having a separate exception, but is
semantically equivalent.

What other information will you want to include in your error
message. For example, will you need to know the id of the
object in question?

Boris



More information about the odb-users mailing list