[odb-users] Creation of ODB cache

Davide Anastasia Davide.Anastasia at qualitycapital.com
Thu May 31 12:42:22 EDT 2012


Hi Boris,
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.

I am currently using ODB in the server-side of a more complex
application, based on messaging between GUI and backend. However, in
some cases, the user might put some wrong data in some field: I would
love to avoid, but unfortunately I can't (it's a long reason why!). 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. Feel free
to ask more, if needed.

Best,
Davide


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: 31 May 2012 17:24
To: Davide Anastasia
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Creation of ODB cache

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?

Boris



More information about the odb-users mailing list