aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-11-23 08:43:35 +0000
committerVincent Richard <[email protected]>2013-11-23 08:43:35 +0000
commitdef78908846541460b9d0142a76bf58732326c99 (patch)
tree46626d28fa40b3b0e1b79b26b884ff67c21d63be
parentDo not throw exception for normal code flow (removed exceptions::no_object_fo... (diff)
downloadvmime-def78908846541460b9d0142a76bf58732326c99.tar.gz
vmime-def78908846541460b9d0142a76bf58732326c99.zip
Do not throw exception for normal code flow. Removed exceptions::no_such_address and exceptions::no_such_mailbox, using std::out_of_range instead.
-rw-r--r--src/addressList.cpp15
-rw-r--r--src/exception.cpp24
-rw-r--r--src/mailboxGroup.cpp15
-rw-r--r--src/mailboxList.cpp27
-rw-r--r--vmime/addressList.hpp11
-rw-r--r--vmime/exception.hpp24
-rw-r--r--vmime/mailboxGroup.hpp11
-rw-r--r--vmime/mailboxList.hpp11
-rw-r--r--vmime/types.hpp1
9 files changed, 52 insertions, 87 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);
}
diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp
index 2958000b..2987b1ac 100644
--- a/vmime/addressList.hpp
+++ b/vmime/addressList.hpp
@@ -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;
diff --git a/vmime/exception.hpp b/vmime/exception.hpp
index 386f9ce0..bb59fe8f 100644
--- a/vmime/exception.hpp
+++ b/vmime/exception.hpp
@@ -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:
diff --git a/vmime/mailboxGroup.hpp b/vmime/mailboxGroup.hpp
index ac6b9741..a85c0232 100644
--- a/vmime/mailboxGroup.hpp
+++ b/vmime/mailboxGroup.hpp
@@ -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;
diff --git a/vmime/mailboxList.hpp b/vmime/mailboxList.hpp
index 25daefec..4003b680 100644
--- a/vmime/mailboxList.hpp
+++ b/vmime/mailboxList.hpp
@@ -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;
diff --git a/vmime/types.hpp b/vmime/types.hpp
index 1a36ea7a..b647d6f5 100644
--- a/vmime/types.hpp
+++ b/vmime/types.hpp
@@ -28,6 +28,7 @@
#include <limits>
#include <string>
#include <vector>
+#include <stdexcept>
#include "vmime/config.hpp"