Do not throw exception for normal code flow. Removed exceptions::no_such_address and exceptions::no_such_mailbox, using std::out_of_range instead.

This commit is contained in:
Vincent Richard 2013-11-23 09:43:35 +01:00
parent 2bbf3eac25
commit def7890884
9 changed files with 52 additions and 87 deletions

View File

@ -151,7 +151,7 @@ void addressList::insertAddressBefore(shared_ptr <address> beforeAddress, shared
(m_list.begin(), m_list.end(), beforeAddress);
if (it == m_list.end())
throw exceptions::no_such_address();
throw std::out_of_range();
m_list.insert(it, addr);
}
@ -159,6 +159,9 @@ void addressList::insertAddressBefore(shared_ptr <address> beforeAddress, shared
void addressList::insertAddressBefore(const size_t pos, shared_ptr <address> addr)
{
if (pos >= m_list.size())
throw std::out_of_range();
m_list.insert(m_list.begin() + pos, addr);
}
@ -169,7 +172,7 @@ void addressList::insertAddressAfter(shared_ptr <address> afterAddress, shared_p
(m_list.begin(), m_list.end(), afterAddress);
if (it == m_list.end())
throw exceptions::no_such_address();
throw std::out_of_range();
m_list.insert(it + 1, addr);
}
@ -177,6 +180,9 @@ void addressList::insertAddressAfter(shared_ptr <address> afterAddress, shared_p
void addressList::insertAddressAfter(const size_t pos, shared_ptr <address> addr)
{
if (pos >= m_list.size())
throw std::out_of_range();
m_list.insert(m_list.begin() + pos + 1, addr);
}
@ -187,7 +193,7 @@ void addressList::removeAddress(shared_ptr <address> addr)
(m_list.begin(), m_list.end(), addr);
if (it == m_list.end())
throw exceptions::no_such_address();
throw std::out_of_range();
m_list.erase(it);
}
@ -195,6 +201,9 @@ void addressList::removeAddress(shared_ptr <address> addr)
void addressList::removeAddress(const size_t pos)
{
if (pos >= m_list.size())
throw std::out_of_range();
const std::vector <shared_ptr <address> >::iterator it = m_list.begin() + pos;
m_list.erase(it);

View File

@ -178,18 +178,6 @@ exception* no_such_part::clone() const { return new no_such_part(*this); }
const char* no_such_part::name() const throw() { return "no_such_part"; }
//
// no_such_mailbox
//
no_such_mailbox::~no_such_mailbox() throw() {}
no_such_mailbox::no_such_mailbox(const exception& other)
: exception("Mailbox not found.", other) {}
exception* no_such_mailbox::clone() const { return new no_such_mailbox(*this); }
const char* no_such_mailbox::name() const throw() { return "no_such_mailbox"; }
//
// no_such_message_id
//
@ -202,18 +190,6 @@ exception* no_such_message_id::clone() const { return new no_such_message_id(*th
const char* no_such_message_id::name() const throw() { return "no_such_message_id"; }
//
// no_such_address
//
no_such_address::~no_such_address() throw() {}
no_such_address::no_such_address(const exception& other)
: exception("Address not found.", other) {}
exception* no_such_address::clone() const { return new no_such_address(*this); }
const char* no_such_address::name() const throw() { return "no_such_address"; }
//
// open_file_error
//

View File

@ -258,7 +258,7 @@ void mailboxGroup::insertMailboxBefore(shared_ptr <mailbox> beforeMailbox, share
(m_list.begin(), m_list.end(), beforeMailbox);
if (it == m_list.end())
throw exceptions::no_such_mailbox();
throw std::out_of_range();
m_list.insert(it, mbox);
}
@ -266,6 +266,9 @@ void mailboxGroup::insertMailboxBefore(shared_ptr <mailbox> beforeMailbox, share
void mailboxGroup::insertMailboxBefore(const size_t pos, shared_ptr <mailbox> mbox)
{
if (pos >= m_list.size())
throw std::out_of_range();
m_list.insert(m_list.begin() + pos, mbox);
}
@ -276,7 +279,7 @@ void mailboxGroup::insertMailboxAfter(shared_ptr <mailbox> afterMailbox, shared_
(m_list.begin(), m_list.end(), afterMailbox);
if (it == m_list.end())
throw exceptions::no_such_mailbox();
throw std::out_of_range();
m_list.insert(it + 1, mbox);
}
@ -284,6 +287,9 @@ void mailboxGroup::insertMailboxAfter(shared_ptr <mailbox> afterMailbox, shared_
void mailboxGroup::insertMailboxAfter(const size_t pos, shared_ptr <mailbox> mbox)
{
if (pos >= m_list.size())
throw std::out_of_range();
m_list.insert(m_list.begin() + pos + 1, mbox);
}
@ -294,7 +300,7 @@ void mailboxGroup::removeMailbox(shared_ptr <mailbox> mbox)
(m_list.begin(), m_list.end(), mbox);
if (it == m_list.end())
throw exceptions::no_such_mailbox();
throw std::out_of_range();
m_list.erase(it);
}
@ -302,6 +308,9 @@ void mailboxGroup::removeMailbox(shared_ptr <mailbox> mbox)
void mailboxGroup::removeMailbox(const size_t pos)
{
if (pos >= m_list.size())
throw std::out_of_range();
const std::vector <shared_ptr <mailbox> >::iterator it = m_list.begin() + pos;
m_list.erase(it);

View File

@ -49,14 +49,7 @@ void mailboxList::appendMailbox(shared_ptr <mailbox> mbox)
void mailboxList::insertMailboxBefore(shared_ptr <mailbox> beforeMailbox, shared_ptr <mailbox> mbox)
{
try
{
m_list.insertAddressBefore(beforeMailbox, mbox);
}
catch (exceptions::no_such_address&)
{
throw exceptions::no_such_mailbox();
}
m_list.insertAddressBefore(beforeMailbox, mbox);
}
@ -68,14 +61,7 @@ void mailboxList::insertMailboxBefore(const size_t pos, shared_ptr <mailbox> mbo
void mailboxList::insertMailboxAfter(shared_ptr <mailbox> afterMailbox, shared_ptr <mailbox> mbox)
{
try
{
m_list.insertAddressAfter(afterMailbox, mbox);
}
catch (exceptions::no_such_address&)
{
throw exceptions::no_such_mailbox();
}
m_list.insertAddressAfter(afterMailbox, mbox);
}
@ -87,14 +73,7 @@ void mailboxList::insertMailboxAfter(const size_t pos, shared_ptr <mailbox> mbox
void mailboxList::removeMailbox(shared_ptr <mailbox> mbox)
{
try
{
m_list.removeAddress(mbox);
}
catch (exceptions::no_such_address&)
{
throw exceptions::no_such_mailbox();
}
m_list.removeAddress(mbox);
}

View File

@ -69,7 +69,7 @@ public:
*
* @param beforeAddress address before which the new address will be inserted
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
* @throw std::out_of_range if the address is not in the list
*/
void insertAddressBefore(shared_ptr <address> beforeAddress, shared_ptr <address> addr);
@ -78,6 +78,7 @@ public:
* @param pos position at which to insert the new address (0 to insert at
* the beginning of the list)
* @param addr address to insert
* @throw std::out_of_range if the position is out of range
*/
void insertAddressBefore(const size_t pos, shared_ptr <address> addr);
@ -85,7 +86,7 @@ public:
*
* @param afterAddress address after which the new address will be inserted
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
* @throw std::out_of_range if the address is not in the list
*/
void insertAddressAfter(shared_ptr <address> afterAddress, shared_ptr <address> addr);
@ -93,19 +94,21 @@ public:
*
* @param pos position of the address before the new address
* @param addr address to insert
* @throw std::out_of_range if the position is out of range
*/
void insertAddressAfter(const size_t pos, shared_ptr <address> addr);
/** Remove the specified address from the list.
*
* @param addr address to remove
* @throw exceptions::no_such_address if the address is not in the list
* @throw std::out_of_range if the address is not in the list
*/
void removeAddress(shared_ptr <address> addr);
/** Remove the address at the specified position.
*
* @param pos position of the address to remove
* @throw std::out_of_range if the position is out of range
*/
void removeAddress(const size_t pos);
@ -129,6 +132,7 @@ public:
*
* @param pos position
* @return address at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
shared_ptr <address> getAddressAt(const size_t pos);
@ -136,6 +140,7 @@ public:
*
* @param pos position
* @return address at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
const shared_ptr <const address> getAddressAt(const size_t pos) const;

View File

@ -188,18 +188,6 @@ public:
};
class VMIME_EXPORT no_such_mailbox : public vmime::exception
{
public:
no_such_mailbox(const exception& other = NO_EXCEPTION);
~no_such_mailbox() throw();
exception* clone() const;
const char* name() const throw();
};
class VMIME_EXPORT no_such_message_id : public vmime::exception
{
public:
@ -212,18 +200,6 @@ public:
};
class VMIME_EXPORT no_such_address : public vmime::exception
{
public:
no_such_address(const exception& other = NO_EXCEPTION);
~no_such_address() throw();
exception* clone() const;
const char* name() const throw();
};
class VMIME_EXPORT open_file_error : public vmime::exception
{
public:

View File

@ -76,7 +76,7 @@ public:
*
* @param beforeMailbox mailbox before which the new mailbox will be inserted
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void insertMailboxBefore(shared_ptr <mailbox> beforeMailbox, shared_ptr <mailbox> mbox);
@ -85,6 +85,7 @@ public:
* @param pos position at which to insert the new mailbox (0 to insert at
* the beginning of the list)
* @param mbox mailbox to insert
* @throw std::out_of_range if the position is out of range
*/
void insertMailboxBefore(const size_t pos, shared_ptr <mailbox> mbox);
@ -92,7 +93,7 @@ public:
*
* @param afterMailbox mailbox after which the new mailbox will be inserted
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void insertMailboxAfter(shared_ptr <mailbox> afterMailbox, shared_ptr <mailbox> mbox);
@ -100,19 +101,21 @@ public:
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
* @throw std::out_of_range if the position is out of range
*/
void insertMailboxAfter(const size_t pos, shared_ptr <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void removeMailbox(shared_ptr <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
* @param pos position of the mailbox to remove
* @throw std::out_of_range if the position is out of range
*/
void removeMailbox(const size_t pos);
@ -136,6 +139,7 @@ public:
*
* @param pos position
* @return mailbox at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
shared_ptr <mailbox> getMailboxAt(const size_t pos);
@ -143,6 +147,7 @@ public:
*
* @param pos position
* @return mailbox at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
const shared_ptr <const mailbox> getMailboxAt(const size_t pos) const;

View File

@ -63,7 +63,7 @@ public:
*
* @param beforeMailbox mailbox before which the new mailbox will be inserted
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void insertMailboxBefore(shared_ptr <mailbox> beforeMailbox, shared_ptr <mailbox> mbox);
@ -72,6 +72,7 @@ public:
* @param pos position at which to insert the new mailbox (0 to insert at
* the beginning of the list)
* @param mbox mailbox to insert
* @throw std::out_of_range if the position is out of range
*/
void insertMailboxBefore(const size_t pos, shared_ptr <mailbox> mbox);
@ -79,7 +80,7 @@ public:
*
* @param afterMailbox mailbox after which the new mailbox will be inserted
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void insertMailboxAfter(shared_ptr <mailbox> afterMailbox, shared_ptr <mailbox> mbox);
@ -87,19 +88,21 @@ public:
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
* @throw std::out_of_range if the position is out of range
*/
void insertMailboxAfter(const size_t pos, shared_ptr <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
* @throw std::out_of_range if the mailbox is not in the list
*/
void removeMailbox(shared_ptr <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
* @param pos position of the mailbox to remove
* @throw std::out_of_range if the position is out of range
*/
void removeMailbox(const size_t pos);
@ -123,6 +126,7 @@ public:
*
* @param pos position
* @return mailbox at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
shared_ptr <mailbox> getMailboxAt(const size_t pos);
@ -130,6 +134,7 @@ public:
*
* @param pos position
* @return mailbox at position 'pos'
* @throw std::out_of_range if the position is out of range
*/
const shared_ptr <const mailbox> getMailboxAt(const size_t pos) const;

View File

@ -28,6 +28,7 @@
#include <limits>
#include <string>
#include <vector>
#include <stdexcept>
#include "vmime/config.hpp"