Don't throw in destructor.

This commit is contained in:
Vincent Richard 2014-11-02 13:09:59 +01:00
parent a32bb6c954
commit 31df6171de
15 changed files with 106 additions and 81 deletions

View File

@ -93,9 +93,9 @@ IMAPConnection::~IMAPConnection()
else if (m_socket) else if (m_socket)
internalDisconnect(); internalDisconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }

View File

@ -65,19 +65,26 @@ IMAPFolder::IMAPFolder(const folder::path& path, shared_ptr <IMAPStore> store, s
IMAPFolder::~IMAPFolder() IMAPFolder::~IMAPFolder()
{ {
shared_ptr <IMAPStore> store = m_store.lock(); try
if (store)
{ {
if (m_open) shared_ptr <IMAPStore> store = m_store.lock();
close(false);
store->unregisterFolder(this); if (store)
{
if (m_open)
close(false);
store->unregisterFolder(this);
}
else if (m_open)
{
m_connection = null;
onClose();
}
} }
else if (m_open) catch (...)
{ {
m_connection = null; // Don't throw in destructor
onClose();
} }
} }

View File

@ -115,10 +115,17 @@ IMAPMessage::IMAPMessage(shared_ptr <IMAPFolder> folder, const int num, const ui
IMAPMessage::~IMAPMessage() IMAPMessage::~IMAPMessage()
{ {
shared_ptr <IMAPFolder> folder = m_folder.lock(); try
{
shared_ptr <IMAPFolder> folder = m_folder.lock();
if (folder) if (folder)
folder->unregisterMessage(this); folder->unregisterMessage(this);
}
catch (...)
{
// Don't throw in destructor
}
} }

View File

@ -57,9 +57,9 @@ IMAPStore::~IMAPStore()
if (isConnected()) if (isConnected())
disconnect(); disconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }
@ -120,15 +120,7 @@ void IMAPStore::connect()
m_connection = make_shared <IMAPConnection> m_connection = make_shared <IMAPConnection>
(dynamicCast <IMAPStore>(shared_from_this()), getAuthenticator()); (dynamicCast <IMAPStore>(shared_from_this()), getAuthenticator());
try m_connection->connect();
{
m_connection->connect();
}
catch (std::exception&)
{
m_connection = null;
throw;
}
} }

View File

@ -60,18 +60,25 @@ maildirFolder::maildirFolder(const folder::path& path, shared_ptr <maildirStore>
maildirFolder::~maildirFolder() maildirFolder::~maildirFolder()
{ {
shared_ptr <maildirStore> store = m_store.lock(); try
if (store)
{ {
if (m_open) shared_ptr <maildirStore> store = m_store.lock();
if (store)
{
if (m_open)
close(false);
store->unregisterFolder(this);
}
else if (m_open)
{
close(false); close(false);
}
store->unregisterFolder(this);
} }
else if (m_open) catch (...)
{ {
close(false); // Don't throw in destructor
} }
} }

View File

@ -58,10 +58,17 @@ maildirMessage::maildirMessage(shared_ptr <maildirFolder> folder, const int num)
maildirMessage::~maildirMessage() maildirMessage::~maildirMessage()
{ {
shared_ptr <maildirFolder> folder = m_folder.lock(); try
{
shared_ptr <maildirFolder> folder = m_folder.lock();
if (folder) if (folder)
folder->unregisterMessage(this); folder->unregisterMessage(this);
}
catch (...)
{
// Don't throw in destructor
}
} }

View File

@ -65,9 +65,9 @@ maildirStore::~maildirStore()
if (isConnected()) if (isConnected())
disconnect(); disconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }

View File

@ -83,9 +83,9 @@ POP3Connection::~POP3Connection()
else if (m_socket) else if (m_socket)
internalDisconnect(); internalDisconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }

View File

@ -56,18 +56,25 @@ POP3Folder::POP3Folder(const folder::path& path, shared_ptr <POP3Store> store)
POP3Folder::~POP3Folder() POP3Folder::~POP3Folder()
{ {
shared_ptr <POP3Store> store = m_store.lock(); try
if (store)
{ {
if (m_open) shared_ptr <POP3Store> store = m_store.lock();
close(false);
store->unregisterFolder(this); if (store)
{
if (m_open)
close(false);
store->unregisterFolder(this);
}
else if (m_open)
{
onClose();
}
} }
else if (m_open) catch (...)
{ {
onClose(); // Don't throw in destructor
} }
} }

View File

@ -53,10 +53,17 @@ POP3Message::POP3Message(shared_ptr <POP3Folder> folder, const int num)
POP3Message::~POP3Message() POP3Message::~POP3Message()
{ {
shared_ptr <POP3Folder> folder = m_folder.lock(); try
{
shared_ptr <POP3Folder> folder = m_folder.lock();
if (folder) if (folder)
folder->unregisterMessage(this); folder->unregisterMessage(this);
}
catch (...)
{
// Don't throw in destructor
}
} }

View File

@ -55,9 +55,9 @@ POP3Store::~POP3Store()
if (isConnected()) if (isConnected())
disconnect(); disconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }
@ -113,15 +113,7 @@ void POP3Store::connect()
m_connection = make_shared <POP3Connection> m_connection = make_shared <POP3Connection>
(dynamicCast <POP3Store>(shared_from_this()), getAuthenticator()); (dynamicCast <POP3Store>(shared_from_this()), getAuthenticator());
try m_connection->connect();
{
m_connection->connect();
}
catch (std::exception&)
{
m_connection = null;
throw;
}
} }

View File

@ -71,9 +71,9 @@ sendmailTransport::~sendmailTransport()
if (isConnected()) if (isConnected())
disconnect(); disconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }

View File

@ -84,9 +84,9 @@ SMTPConnection::~SMTPConnection()
else if (m_socket) else if (m_socket)
internalDisconnect(); internalDisconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }

View File

@ -64,9 +64,9 @@ SMTPTransport::~SMTPTransport()
if (isConnected()) if (isConnected())
disconnect(); disconnect();
} }
catch (vmime::exception&) catch (...)
{ {
// Ignore // Don't throw in destructor
} }
} }
@ -91,15 +91,7 @@ void SMTPTransport::connect()
m_connection = make_shared <SMTPConnection> m_connection = make_shared <SMTPConnection>
(dynamicCast <SMTPTransport>(shared_from_this()), getAuthenticator()); (dynamicCast <SMTPTransport>(shared_from_this()), getAuthenticator());
try m_connection->connect();
{
m_connection->connect();
}
catch (std::exception&)
{
m_connection = null;
throw;
}
} }

View File

@ -257,12 +257,19 @@ TLSSession_GnuTLS::TLSSession_GnuTLS(const TLSSession_GnuTLS&)
TLSSession_GnuTLS::~TLSSession_GnuTLS() TLSSession_GnuTLS::~TLSSession_GnuTLS()
{ {
if (m_gnutlsSession) try
{ {
gnutls_deinit(*m_gnutlsSession); if (m_gnutlsSession)
{
gnutls_deinit(*m_gnutlsSession);
delete m_gnutlsSession; delete m_gnutlsSession;
m_gnutlsSession = NULL; m_gnutlsSession = NULL;
}
}
catch (...)
{
// Don't throw in destructor
} }
} }