#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() ~MySQLConnectorRegistrator()
/// Calls Poco::Data::MySQL::unregisterConnector(); /// 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() ~ODBCConnectorRegistrator()
/// Calls Poco::Data::ODBC::unregisterConnector(); /// 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() ~Handle()
/// Destroys the Handle. /// Destroys the Handle.
{ {
try
{
#if defined(_DEBUG) #if defined(_DEBUG)
SQLRETURN rc = SQLRETURN rc =
#endif #endif
SQLFreeHandle(handleType, _handle); SQLFreeHandle(handleType, _handle);
// N.B. Destructors should not throw, but neither do we want to // 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. // leak resources. So, we throw here in debug mode if things go bad.
poco_assert_dbg (!Utility::isError(rc)); poco_assert_dbg (!Utility::isError(rc));
}
catch (...)
{
poco_unexpected();
}
} }
operator const H& () const operator const H& () const

View File

@ -40,12 +40,19 @@ ConnectionHandle::ConnectionHandle(EnvironmentHandle* pEnvironment):
ConnectionHandle::~ConnectionHandle() ConnectionHandle::~ConnectionHandle()
{ {
SQLDisconnect(_hdbc); try
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_DBC, _hdbc); {
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() EnvironmentHandle::~EnvironmentHandle()
{ {
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_ENV, _henv); try
poco_assert (!Utility::isError(rc)); {
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() Preparator::~Preparator()
{ {
freeMemory(); try
{
freeMemory();
}
catch (...)
{
poco_unexpected();
}
} }

View File

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

View File

@ -104,7 +104,14 @@ struct SQLite_API SQLiteConnectorRegistrator
~SQLiteConnectorRegistrator() ~SQLiteConnectorRegistrator()
/// Calls Poco::Data::SQLite::unregisterConnector(); /// 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() Notifier::~Notifier()
{ {
disableAll(); try
{
disableAll();
}
catch (...)
{
poco_unexpected();
}
} }

View File

@ -52,7 +52,14 @@ SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqli
SQLiteStatementImpl::~SQLiteStatementImpl() 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() SessionImpl::~SessionImpl()
{ {
close(); try
{
close();
}
catch (...)
{
poco_unexpected();
}
} }