#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

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

View File

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

View File

@ -57,6 +57,8 @@ public:
~Handle() ~Handle()
/// Destroys the Handle. /// Destroys the Handle.
{ {
try
{
#if defined(_DEBUG) #if defined(_DEBUG)
SQLRETURN rc = SQLRETURN rc =
#endif #endif
@ -65,6 +67,11 @@ public:
// 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
/// Const conversion operator into reference to native type. /// Const conversion operator into reference to native type.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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