Having a destructor take different actions depending on whether an exception occurred
- by dan04
I have some code to update a database table that looks like
try
{
db.execute("BEGIN");
// Lots of DELETE and INSERT
db.execute("COMMIT");
}
catch (DBException&)
{
db.execute("ROLLBACK");
}
I'd like to wrap the transaction logic in an RAII class so I could just write
{
DBTransaction trans(db);
// Lots of DELETE and INSERT
}
but how would I write the destructor for it?