Код: Выделить всё
class DBConn
{
public:
//...
void close() // Exposed to allow users to react to exceptions
{
db.close();
closed = true;
}
~DBConn() // Use RAII to automatically call close
{
if (!closed) // This is not set to true if close was called and the user has handled the exception
{
try {
db.close();
}
catch(...)
{
// terminate or swallow the exception
}
}
}
private:
DBConnection db; // Object with just a close method that may throw
bool closed;
};
Подробнее здесь: https://stackoverflow.com/questions/796 ... rd-edition