[odb-users] Creation of ODB cache

Boris Kolpackov boris at codesynthesis.com
Thu May 31 12:24:16 EDT 2012

Hi Davide,

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

> Suppose I try to read from the database an object using load<OBJ>(KEY)
> and the KEY does not exist, I get an exception of type
> object_not_persistent. That's fair. However, I would love to have a
> different exception for each persistent type: is it that possible
> somehow?

No, not at the moment. We were thinking about adding some kind of
type information (and maybe object id) in some way, but there doesn't
seem to be good way to do this in a type-independent way.

I guess throwing a type-specific exception would be one way to do
it. The problem, of course, is the potential code bloat that it
would lead to.

Another option would to add an std::type_info reference that would
identify the class.

> It would be great to be able to do something like:
> Try
> {
>   Shared_ptr<obj1> myObj1 = db.load<obj1>(keyObj1);
>   Shared_ptr<obj2> myObj2 = db.load<obj2>(keyObj2);
> }
> Catch (const obj1_not_persistent& ex)
> {
>   ...
> }
> Catch (const obj2_not_persistent& ex)
> {
>    ...
> }

What would you do in the catch() {} blocks? In other words, what
type-dependant actions are you planning to do?


More information about the odb-users mailing list