diff options
Diffstat (limited to '')
-rw-r--r-- | src/addressList.cpp | 15 | ||||
-rw-r--r-- | src/exception.cpp | 24 | ||||
-rw-r--r-- | src/mailboxGroup.cpp | 15 | ||||
-rw-r--r-- | src/mailboxList.cpp | 27 |
4 files changed, 27 insertions, 54 deletions
diff --git a/src/addressList.cpp b/src/addressList.cpp index 957be503..756156d1 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -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); diff --git a/src/exception.cpp b/src/exception.cpp index e1f40ce4..45f672a3 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -179,18 +179,6 @@ 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 // @@ -203,18 +191,6 @@ const char* no_such_message_id::name() const throw() { return "no_such_message_i // -// 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 // diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp index 559d8778..d4bbb7db 100644 --- a/src/mailboxGroup.cpp +++ b/src/mailboxGroup.cpp @@ -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); diff --git a/src/mailboxList.cpp b/src/mailboxList.cpp index 0a76c52a..7d6674fc 100644 --- a/src/mailboxList.cpp +++ b/src/mailboxList.cpp @@ -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); } |