Enhance exception throwing with Boost Exception library

Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/util/config-file.cpp b/src/util/config-file.cpp
index a68939d..ebf2a7a 100644
--- a/src/util/config-file.cpp
+++ b/src/util/config-file.cpp
@@ -123,11 +123,11 @@
 {
   if (m_path.empty())
     {
-      throw Error("Failed to locate configuration file for parsing");
+      BOOST_THROW_EXCEPTION(Error("Failed to locate configuration file for parsing"));
     }
   else if (!m_input.is_open() && !open())
     {
-      throw Error("Failed to open configuration file for parsing");
+      BOOST_THROW_EXCEPTION(Error("Failed to open configuration file for parsing"));
     }
 
   try
@@ -140,7 +140,7 @@
       msg << "Failed to parse configuration file";
       msg << " " << m_path;
       msg << " " << error.message() << " line " << error.line();
-      throw Error(msg.str());
+      BOOST_THROW_EXCEPTION(Error(msg.str()));
     }
   return m_config;
 }
diff --git a/src/util/digest.cpp b/src/util/digest.cpp
index d5bb312..23af4c9 100644
--- a/src/util/digest.cpp
+++ b/src/util/digest.cpp
@@ -126,7 +126,7 @@
 {
   // cannot update Digest when it has been finalized
   if (m_isFinalized)
-    throw Error("Digest has been already finalized");
+    BOOST_THROW_EXCEPTION(Error("Digest has been already finalized"));
 
   m_hash.Update(buffer, size);
 
diff --git a/src/util/dns.cpp b/src/util/dns.cpp
index 03bf9f9..7c992ff 100644
--- a/src/util/dns.cpp
+++ b/src/util/dns.cpp
@@ -151,7 +151,7 @@
           return EndPoint(*remoteEndpoint).address();
         }
     }
-  throw Error("No endpoint matching the specified address selector found");
+  BOOST_THROW_EXCEPTION(Error("No endpoint matching the specified address selector found"));
 }
 
 } // namespace dns
diff --git a/src/util/face-uri.cpp b/src/util/face-uri.cpp
index ff5669b..f23ae8c 100644
--- a/src/util/face-uri.cpp
+++ b/src/util/face-uri.cpp
@@ -48,14 +48,14 @@
 FaceUri::FaceUri(const std::string& uri)
 {
   if (!parse(uri)) {
-    throw Error("Malformed URI: " + uri);
+    BOOST_THROW_EXCEPTION(Error("Malformed URI: " + uri));
   }
 }
 
 FaceUri::FaceUri(const char* uri)
 {
   if (!parse(uri)) {
-    throw Error("Malformed URI: " + std::string(uri));
+    BOOST_THROW_EXCEPTION(Error("Malformed URI: " + std::string(uri)));
   }
 }
 
diff --git a/src/util/in-memory-storage.cpp b/src/util/in-memory-storage.cpp
index 9c3146f..5001e97 100644
--- a/src/util/in-memory-storage.cpp
+++ b/src/util/in-memory-storage.cpp
@@ -125,7 +125,7 @@
     ssize_t nAllowedFailures = size() - m_capacity;
     while (size() > m_capacity) {
       if (!evictItem() && --nAllowedFailures < 0) {
-        throw Error();
+        BOOST_THROW_EXCEPTION(Error());
       }
     }
   }
diff --git a/src/util/io.hpp b/src/util/io.hpp
index f49d712..f751bc6 100644
--- a/src/util/io.hpp
+++ b/src/util/io.hpp
@@ -148,15 +148,15 @@
     }
   catch (TypeError& e)
     {
-      throw Error(e.what());
+      BOOST_THROW_EXCEPTION(Error(e.what()));
     }
   catch (CryptoPP::Exception& e)
     {
-      throw Error(e.what());
+      BOOST_THROW_EXCEPTION(Error(e.what()));
     }
   catch (tlv::Error& e)
     {
-      throw Error(e.what());
+      BOOST_THROW_EXCEPTION(Error(e.what()));
     }
 }
 
diff --git a/src/util/network-monitor.cpp b/src/util/network-monitor.cpp
index 5513d0d..8f7b1f9 100644
--- a/src/util/network-monitor.cpp
+++ b/src/util/network-monitor.cpp
@@ -165,7 +165,8 @@
   {
     int fd = ::socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
     if (fd < 0)
-      throw Error(std::string("Cannot create netlink socket (") + std::strerror(errno) + ")");
+      BOOST_THROW_EXCEPTION(Error(std::string("Cannot create netlink socket (") +
+                                  std::strerror(errno) + ")"));
 
     sockaddr_nl addr{};
     addr.nl_family = AF_NETLINK;
@@ -174,7 +175,8 @@
       RTMGRP_IPV6_IFADDR | RTMGRP_IPV6_ROUTE;
 
     if (::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == -1) {
-      throw Error(std::string("Cannot bind on netlink socket (") + std::strerror(errno) + ")");
+      BOOST_THROW_EXCEPTION(Error(std::string("Cannot bind on netlink socket (") +
+                                  std::strerror(errno) + ")"));
     }
 
     m_socket.assign(fd);
@@ -239,7 +241,7 @@
 
 NetworkMonitor::NetworkMonitor(boost::asio::io_service&)
 {
-  throw Error("Network monitoring is not supported on this platform");
+  BOOST_THROW_EXCEPTION(Error("Network monitoring is not supported on this platform"));
 }
 
 NetworkMonitor::~NetworkMonitor()
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index 1174541..77efd83 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -69,7 +69,7 @@
 RegexBackrefMatcher::compile()
 {
   if (m_expr.size() < 2)
-    throw RegexMatcher::Error("Unrecognized format: " + m_expr);
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Unrecognized format: " + m_expr));
 
   size_t lastIndex = m_expr.size() - 1;
   if ('(' == m_expr[0] && ')' == m_expr[lastIndex]) {
@@ -80,7 +80,7 @@
     m_matchers.push_back(matcher);
   }
   else
-    throw RegexMatcher::Error("Unrecognized format: " + m_expr);
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Unrecognized format: " + m_expr));
 }
 
 
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 6b5474a..029bb03 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -136,7 +136,8 @@
     }
   else
     {
-      throw RegexMatcher::Error("Non-exact component search is not supported yet!");
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Non-exact component search is not supported "
+                                                "yet"));
     }
 
   return false;
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index 9c2ff16..b20ad44 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -92,7 +92,8 @@
 RegexComponentSetMatcher::compile()
 {
   if (m_expr.size() < 2)
-    throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Regexp compile error (cannot parse " +
+                                              m_expr + ")"));
 
   switch (m_expr[0]) {
   case '<':
@@ -101,7 +102,8 @@
     {
       size_t lastIndex = m_expr.size() - 1;
       if (']' != m_expr[lastIndex])
-        throw RegexMatcher::Error("Regexp compile error (no matching ']' in " + m_expr + ")");
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error("Regexp compile error (no matching ']' in " +
+                                                  m_expr + ")"));
 
       if ('^' == m_expr[1]) {
         m_isInclusion = false;
@@ -112,7 +114,8 @@
       break;
     }
   default:
-    throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Regexp compile error (cannot parse " +
+                                              m_expr + ")"));
   }
 }
 
@@ -123,7 +126,7 @@
 
   if (m_expr.size() != end)
     {
-      throw RegexMatcher::Error("Component expr error " + m_expr);
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Component expr error " + m_expr));
     }
   else
     {
@@ -142,7 +145,7 @@
 
   while (index < lastIndex) {
     if ('<' != m_expr[index])
-      throw RegexMatcher::Error("Component expr error " + m_expr);
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Component expr error " + m_expr));
 
     tempIndex = index + 1;
     index = extractComponent(tempIndex);
@@ -155,7 +158,7 @@
   }
 
   if (index != lastIndex)
-    throw RegexMatcher::Error("Not sufficient expr to parse " + m_expr);
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Not sufficient expr to parse " + m_expr));
 }
 
 inline bool
@@ -208,7 +211,7 @@
       break;
 
     case 0:
-      throw RegexMatcher::Error("Error: square brackets mismatch");
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Error: square brackets mismatch"));
       break;
     }
     index++;
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index acca0f9..fedcbaa 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -86,7 +86,7 @@
     subHead = index;
 
     if (!extractPattern(subHead, &index))
-      throw RegexMatcher::Error("Compile error");
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Compile error"));
   }
 }
 
@@ -135,7 +135,7 @@
     break;
 
   default:
-    throw RegexMatcher::Error("Unexpected syntax");
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("Unexpected syntax"));
   }
 
   *next = end;
@@ -152,7 +152,7 @@
   while (lcount > rcount) {
 
     if (index >= m_expr.size())
-      throw RegexMatcher::Error("Parenthesis mismatch");
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Parenthesis mismatch"));
 
     if (left == m_expr[index])
       lcount++;
@@ -184,7 +184,7 @@
         break;
     }
     if (index == exprSize)
-      throw RegexMatcher::Error("Missing right brace bracket");
+      BOOST_THROW_EXCEPTION(RegexMatcher::Error("Missing right brace bracket"));
     else
       return ++index;
   }
diff --git a/src/util/regex/regex-repeat-matcher.hpp b/src/util/regex/regex-repeat-matcher.hpp
index 3d6e4f5..530721e 100644
--- a/src/util/regex/regex-repeat-matcher.hpp
+++ b/src/util/regex/regex-repeat-matcher.hpp
@@ -162,12 +162,12 @@
         max = min;
       }
       else
-        throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
-                                  + "Unrecognized format "+ m_expr);
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
+                                                  + " Unrecognized format "+ m_expr));
 
       if (min > MAX_REPETITIONS || max > MAX_REPETITIONS || min > max)
-        throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
-                                  + "Wrong number " + m_expr);
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition():")
+                                                  + " Wrong number " + m_expr));
 
       m_repeatMin = min;
       m_repeatMax = max;
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index 5ed4937..30b755f 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -146,7 +146,7 @@
                 result.append(*it);
             }
           else
-            throw RegexMatcher::Error("Exceed the range of back reference");
+            BOOST_THROW_EXCEPTION(RegexMatcher::Error("Exceed the range of back reference"));
         }
     }
   return result;
@@ -161,23 +161,23 @@
     {
       offset++;
       if (offset >= expand.size())
-        throw RegexMatcher::Error("wrong format of expand string!");
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
 
       while (expand[offset] <= '9' and expand[offset] >= '0') {
         offset++;
         if (offset > expand.size())
-          throw RegexMatcher::Error("wrong format of expand string!");
+          BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
       }
       if (offset > begin + 1)
         return expand.substr(begin, offset - begin);
       else
-        throw RegexMatcher::Error("wrong format of expand string!");
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
     }
   else if (expand[offset] == '<')
     {
       offset++;
       if (offset >= expand.size())
-        throw RegexMatcher::Error("wrong format of expand string!");
+        BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
 
       size_t left = 1;
       size_t right = 0;
@@ -189,12 +189,12 @@
             right++;
           offset++;
           if (offset >= expand.size())
-            throw RegexMatcher::Error("wrong format of expand string!");
+            BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
         }
       return expand.substr(begin, offset - begin);
     }
   else
-    throw RegexMatcher::Error("wrong format of expand string!");
+    BOOST_THROW_EXCEPTION(RegexMatcher::Error("wrong format of expand string!"));
 }
 
 shared_ptr<RegexTopMatcher>
diff --git a/src/util/sqlite3-statement.cpp b/src/util/sqlite3-statement.cpp
index 243088b..f1871db 100644
--- a/src/util/sqlite3-statement.cpp
+++ b/src/util/sqlite3-statement.cpp
@@ -35,7 +35,7 @@
 {
   int res = sqlite3_prepare_v2(database, statement.c_str(), -1, &m_stmt, nullptr);
   if (res != SQLITE_OK)
-    throw std::domain_error("bad SQL statement: " + statement);
+    BOOST_THROW_EXCEPTION(std::domain_error("bad SQL statement: " + statement));
 }
 
 int
diff --git a/src/util/string-helper.cpp b/src/util/string-helper.cpp
index fc0e1a1..16064b0 100644
--- a/src/util/string-helper.cpp
+++ b/src/util/string-helper.cpp
@@ -89,7 +89,8 @@
 fromHex(const std::string& hexString)
 {
   if (hexString.size() % 2 != 0) {
-    throw StringHelperError("Invalid number of characters in the supplied hex string");
+    BOOST_THROW_EXCEPTION(StringHelperError("Invalid number of characters in the supplied hex "
+                                            "string"));
   }
 
   using namespace CryptoPP;
@@ -99,7 +100,7 @@
   shared_ptr<const Buffer> buffer = os.buf();
 
   if (buffer->size() * 2 != hexString.size()) {
-    throw StringHelperError("The supplied hex string contains non-hex characters");
+    BOOST_THROW_EXCEPTION(StringHelperError("The supplied hex string contains non-hex characters"));
   }
 
   return buffer;