Use the following:
transaction tr(db); ... tr.commit();
When tr.commit() completes, it sets the state to "commit done", and the destructor does nothing, otherwise it rolls back.
Exception checking is a bad idea, think:
transaction tr(db); ... if(something_wrong) return;
In this case, you probably expect rollback rather than commit, but the commit will complete.
Edit: but if you still want this bad, look at std::uncaught_exception() , but read this first http://www.gotw.ca/gotw/047.htm
Artyom
source share