[odb-users] Catch Exception Problem

Tarik BENZ tenchu.tarik at hotmail.fr
Thu May 30 11:16:58 EDT 2013


Hello,

I am trying to persist a new object in the DB, but I have an constraint integrity exception.
The problem is that this exception is not caught by my code. I am doing something wrong
but I don't know what.

My code is :

template<typename Type> bool CreateNewObject(Type * object)
{
    if(object != NULL)
    {
        transaction * transact = NULL;
        try
        {
            std::unique_ptr<odb::database> db (create_database());
            transact  = new transaction (db->begin());

            // Make object persistent.
            db->persist((*object));
            transact->commit();
        }
        catch (const odb::exception& e)
        {
            cerr << e.what () << endl;
            if(transact != NULL)
            {
                transact->rollback();
            }
        }
    }
    return false;
}

Can someone help me please?

Best,
 Tarik
 		 	   		  


More information about the odb-users mailing list