#538 prevent destructors from throwing exceptions

This commit is contained in:
Guenter Obiltschnig 2014-09-19 10:13:03 +02:00
parent 5a14f72508
commit 85fd968a1e
11 changed files with 100 additions and 24 deletions

View File

@ -85,7 +85,14 @@ struct MySQL_API MySQLConnectorRegistrator
~MySQLConnectorRegistrator()
/// Calls Poco::Data::MySQL::unregisterConnector();
{
Poco::Data::MySQL::Connector::unregisterConnector();
try
{
Poco::Data::MySQL::Connector::unregisterConnector();
}
catch (...)
{
poco_unexpected();
}
}
};

View File

@ -96,7 +96,14 @@ struct ODBC_API ODBCConnectorRegistrator
~ODBCConnectorRegistrator()
/// Calls Poco::Data::ODBC::unregisterConnector();
{
Poco::Data::ODBC::Connector::unregisterConnector();
try
{
Poco::Data::ODBC::Connector::unregisterConnector();
}
catch (...)
{
poco_unexpected();
}
}
};

View File

@ -57,13 +57,20 @@ public:
~Handle()
/// Destroys the Handle.
{
try
{
#if defined(_DEBUG)
SQLRETURN rc =
SQLRETURN rc =
#endif
SQLFreeHandle(handleType, _handle);
// N.B. Destructors should not throw, but neither do we want to
// leak resources. So, we throw here in debug mode if things go bad.
poco_assert_dbg (!Utility::isError(rc));
SQLFreeHandle(handleType, _handle);
// N.B. Destructors should not throw, but neither do we want to
// leak resources. So, we throw here in debug mode if things go bad.
poco_assert_dbg (!Utility::isError(rc));
}
catch (...)
{
poco_unexpected();
}
}
operator const H& () const

View File

@ -40,12 +40,19 @@ ConnectionHandle::ConnectionHandle(EnvironmentHandle* pEnvironment):
ConnectionHandle::~ConnectionHandle()
{
SQLDisconnect(_hdbc);
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_DBC, _hdbc);
try
{
SQLDisconnect(_hdbc);
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_DBC, _hdbc);
if (_ownsEnvironment) delete _pEnvironment;
if (_ownsEnvironment) delete _pEnvironment;
poco_assert (!Utility::isError(rc));
poco_assert (!Utility::isError(rc));
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -41,8 +41,15 @@ EnvironmentHandle::EnvironmentHandle(): _henv(SQL_NULL_HENV)
EnvironmentHandle::~EnvironmentHandle()
{
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_ENV, _henv);
poco_assert (!Utility::isError(rc));
try
{
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_ENV, _henv);
poco_assert (!Utility::isError(rc));
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -52,7 +52,14 @@ Preparator::Preparator(const Preparator& other):
Preparator::~Preparator()
{
freeMemory();
try
{
freeMemory();
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -70,14 +70,20 @@ SessionImpl::SessionImpl(const std::string& connect,
SessionImpl::~SessionImpl()
{
if (isTransaction() && !getFeature("autoCommit"))
try
{
try { rollback(); }
catch (...) { }
}
if (isTransaction() && !getFeature("autoCommit"))
{
try { rollback(); }
catch (...) { }
}
try { close(); }
catch (...) { }
close();
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -104,7 +104,14 @@ struct SQLite_API SQLiteConnectorRegistrator
~SQLiteConnectorRegistrator()
/// Calls Poco::Data::SQLite::unregisterConnector();
{
Poco::Data::SQLite::Connector::unregisterConnector();
try
{
Poco::Data::SQLite::Connector::unregisterConnector();
}
catch (...)
{
poco_unexpected();
}
}
};

View File

@ -45,7 +45,14 @@ Notifier::Notifier(const Session& session, const Any& value, EnabledEventType en
Notifier::~Notifier()
{
disableAll();
try
{
disableAll();
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -52,7 +52,14 @@ SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqli
SQLiteStatementImpl::~SQLiteStatementImpl()
{
clear();
try
{
clear();
}
catch (...)
{
poco_unexpected();
}
}

View File

@ -57,7 +57,14 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
SessionImpl::~SessionImpl()
{
close();
try
{
close();
}
catch (...)
{
poco_unexpected();
}
}