Enhance exception throwing with Boost Exception library

Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4919aa
Refs: #2541
diff --git a/daemon/mgmt/command-validator.cpp b/daemon/mgmt/command-validator.cpp
index 396cfe4..715b5d5 100644
--- a/daemon/mgmt/command-validator.cpp
+++ b/daemon/mgmt/command-validator.cpp
@@ -75,7 +75,7 @@
 
   if (section.begin() == section.end())
     {
-      throw ConfigFile::Error("No authorize sections found");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("No authorize sections found"));
     }
 
   std::stringstream dryRunErrors;
@@ -92,7 +92,7 @@
           std::string msg = "No certfile specified";
           if (!isDryRun)
             {
-              throw ConfigFile::Error(msg);
+              BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
             }
           aggregateErrors(dryRunErrors, msg);
           continue;
@@ -112,7 +112,7 @@
               std::string msg = "Unable to open certificate file " + certfilePath.native();
               if (!isDryRun)
                 {
-                  throw ConfigFile::Error(msg);
+                  BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
                 }
               aggregateErrors(dryRunErrors, msg);
               continue;
@@ -131,7 +131,7 @@
             std::string msg = "Malformed certificate file " + certfilePath.native();
             if (!isDryRun)
               {
-                throw ConfigFile::Error(msg);
+                BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
               }
             aggregateErrors(dryRunErrors, msg);
             continue;
@@ -160,7 +160,7 @@
             certfile + " (" + keyNameForLogging + ")";
           if (!isDryRun)
             {
-              throw ConfigFile::Error(msg);
+              BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
             }
           aggregateErrors(dryRunErrors, msg);
           continue;
@@ -196,7 +196,7 @@
                 "\" for certificate file " + certfile + " (" + keyNameForLogging + ")";
               if (!isDryRun)
                 {
-                  throw ConfigFile::Error(msg);
+                  BOOST_THROW_EXCEPTION(ConfigFile::Error(msg));
                 }
               aggregateErrors(dryRunErrors, msg);
             }
@@ -205,7 +205,7 @@
 
   if (!dryRunErrors.str().empty())
     {
-      throw ConfigFile::Error(dryRunErrors.str());
+      BOOST_THROW_EXCEPTION(ConfigFile::Error(dryRunErrors.str()));
     }
 }
 
@@ -214,7 +214,7 @@
 {
   if (m_supportedPrivileges.find(privilege) != m_supportedPrivileges.end())
     {
-      throw CommandValidator::Error("Duplicated privilege: " + privilege);
+      BOOST_THROW_EXCEPTION(CommandValidator::Error("Duplicated privilege: " + privilege));
     }
   m_supportedPrivileges.insert(privilege);
 }
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index eecf25c..692acf9 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -173,7 +173,7 @@
       if (item.first == "unix")
         {
           if (hasSeenUnix)
-            throw Error("Duplicate \"unix\" section");
+            BOOST_THROW_EXCEPTION(Error("Duplicate \"unix\" section"));
           hasSeenUnix = true;
 
           processSectionUnix(item.second, isDryRun);
@@ -181,7 +181,7 @@
       else if (item.first == "tcp")
         {
           if (hasSeenTcp)
-            throw Error("Duplicate \"tcp\" section");
+            BOOST_THROW_EXCEPTION(Error("Duplicate \"tcp\" section"));
           hasSeenTcp = true;
 
           processSectionTcp(item.second, isDryRun);
@@ -189,7 +189,7 @@
       else if (item.first == "udp")
         {
           if (hasSeenUdp)
-            throw Error("Duplicate \"udp\" section");
+            BOOST_THROW_EXCEPTION(Error("Duplicate \"udp\" section"));
           hasSeenUdp = true;
 
           processSectionUdp(item.second, isDryRun, nicList);
@@ -197,7 +197,7 @@
       else if (item.first == "ether")
         {
           if (hasSeenEther)
-            throw Error("Duplicate \"ether\" section");
+            BOOST_THROW_EXCEPTION(Error("Duplicate \"ether\" section"));
           hasSeenEther = true;
 
           processSectionEther(item.second, isDryRun, nicList);
@@ -205,14 +205,14 @@
       else if (item.first == "websocket")
         {
           if (hasSeenWebSocket)
-            throw Error("Duplicate \"websocket\" section");
+            BOOST_THROW_EXCEPTION(Error("Duplicate \"websocket\" section"));
           hasSeenWebSocket = true;
 
           processSectionWebSocket(item.second, isDryRun);
         }
       else
         {
-          throw Error("Unrecognized option \"" + item.first + "\"");
+          BOOST_THROW_EXCEPTION(Error("Unrecognized option \"" + item.first + "\""));
         }
     }
 }
@@ -240,7 +240,8 @@
         }
       else
         {
-          throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"unix\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + i->first + "\" in "
+                                                  "\"unix\" section"));
         }
     }
 
@@ -269,8 +270,8 @@
       m_factories.insert(std::make_pair("unix", factory));
     }
 #else
-  throw ConfigFile::Error("NFD was compiled without Unix sockets support, "
-                          "cannot process \"unix\" section");
+  BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without Unix sockets support, "
+                                          "cannot process \"unix\" section"));
 #endif // HAVE_UNIX_SOCKETS
 
 }
@@ -304,8 +305,8 @@
             }
           catch (const std::bad_cast& error)
             {
-              throw ConfigFile::Error("Invalid value for option " +
-                                      i->first + "\" in \"tcp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option " +
+                                                      i->first + "\" in \"tcp\" section"));
             }
         }
       else if (i->first == "listen")
@@ -322,15 +323,16 @@
         }
       else
         {
-          throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"tcp\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + i->first + "\" in "
+                                                  "\"tcp\" section"));
         }
     }
 
   if (!enableV4 && !enableV6)
     {
-      throw ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
-                              " Remove \"tcp\" section to disable TCP channels or"
-                              " re-enable at least one channel type.");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
+                                              " Remove \"tcp\" section to disable TCP channels or"
+                                              " re-enable at least one channel type."));
     }
 
   if (!isDryRun)
@@ -413,8 +415,8 @@
             }
           catch (const std::bad_cast& error)
             {
-              throw ConfigFile::Error("Invalid value for option " +
-                                      i->first + "\" in \"udp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option " +
+                                                      i->first + "\" in \"udp\" section"));
             }
         }
       else if (i->first == "enable_v4")
@@ -433,8 +435,8 @@
             }
           catch (const std::exception& e)
             {
-              throw ConfigFile::Error("Invalid value for option \"" +
-                                      i->first + "\" in \"udp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                                      i->first + "\" in \"udp\" section"));
             }
         }
       else if (i->first == "keep_alive_interval")
@@ -448,8 +450,8 @@
             }
           catch (const std::exception& e)
             {
-              throw ConfigFile::Error("Invalid value for option \"" +
-                                      i->first + "\" in \"udp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                                      i->first + "\" in \"udp\" section"));
             }
         }
       else if (i->first == "mcast")
@@ -466,8 +468,8 @@
             }
           catch (const std::bad_cast& error)
             {
-              throw ConfigFile::Error("Invalid value for option " +
-                                      i->first + "\" in \"udp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option " +
+                                                      i->first + "\" in \"udp\" section"));
             }
         }
       else if (i->first == "mcast_group")
@@ -479,32 +481,34 @@
               address mcastGroupTest = address::from_string(mcastGroup);
               if (!mcastGroupTest.is_v4())
                 {
-                  throw ConfigFile::Error("Invalid value for option \"" +
-                                          i->first + "\" in \"udp\" section");
+                  BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                                          i->first + "\" in \"udp\" section"));
                 }
             }
           catch(const std::runtime_error& e)
             {
-              throw ConfigFile::Error("Invalid value for option \"" +
-                                      i->first + "\" in \"udp\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                                      i->first + "\" in \"udp\" section"));
             }
         }
       else
         {
-          throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"udp\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + i->first + "\" in "
+                                                  "\"udp\" section"));
         }
     }
 
   if (!enableV4 && !enableV6)
     {
-      throw ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
-                              " Remove \"udp\" section to disable UDP channels or"
-                              " re-enable at least one channel type.");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
+                                              " Remove \"udp\" section to disable UDP channels or"
+                                              " re-enable at least one channel type."));
     }
   else if (useMcast && !enableV4)
     {
-      throw ConfigFile::Error("IPv4 multicast requested, but IPv4 channels"
-                              " have been disabled (conflicting configuration options set)");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 multicast requested, but IPv4 channels"
+                                              " have been disabled (conflicting configuration"
+                                              " options set)"));
     }
 
   /// \todo what is keep alive interval used for?
@@ -645,13 +649,14 @@
           mcastGroup = ethernet::Address::fromString(i->second.get_value<std::string>());
           if (mcastGroup.isNull())
             {
-              throw ConfigFile::Error("Invalid value for option \"" +
-                                      i->first + "\" in \"ether\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                                      i->first + "\" in \"ether\" section"));
             }
         }
       else
         {
-          throw ConfigFile::Error("Unrecognized option \"" + i->first + "\" in \"ether\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" + i->first +
+                                                  "\" in \"ether\" section"));
         }
     }
 
@@ -729,7 +734,8 @@
         }
     }
 #else
-  throw ConfigFile::Error("NFD was compiled without libpcap, cannot process \"ether\" section");
+  BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without libpcap, cannot "
+                                          "process \"ether\" section"));
 #endif // HAVE_LIBPCAP
 }
 
@@ -766,8 +772,8 @@
             }
           catch (const std::bad_cast& error)
             {
-              throw ConfigFile::Error("Invalid value for option " +
-                                      i->first + "\" in \"websocket\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option " +
+                                                      i->first + "\" in \"websocket\" section"));
             }
         }
       else if (i->first == "listen")
@@ -784,21 +790,21 @@
         }
       else
         {
-          throw ConfigFile::Error("Unrecognized option \"" +
-                                  i->first + "\" in \"websocket\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Unrecognized option \"" +
+                                                  i->first + "\" in \"websocket\" section"));
         }
     }
 
   if (!enableV4 && !enableV6)
     {
-      throw ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
-                              " Remove \"websocket\" section to disable WebSocket channels or"
-                              " re-enable at least one channel type.");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("IPv4 and IPv6 channels have been disabled."
+                                              " Remove \"websocket\" section to disable WebSocket"
+                                              " channels or re-enable at least one channel type."));
     }
 
   if (!enableV4 && enableV6)
     {
-      throw ConfigFile::Error("NFD does not allow pure IPv6 WebSocket channel.");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD does not allow pure IPv6 WebSocket channel."));
     }
 
   if (!isDryRun)
@@ -833,8 +839,8 @@
         }
     }
 #else
-  throw ConfigFile::Error("NFD was compiled without WebSocket, "
-                          "cannot process \"websocket\" section");
+  BOOST_THROW_EXCEPTION(ConfigFile::Error("NFD was compiled without WebSocket, "
+                                          "cannot process \"websocket\" section"));
 #endif // HAVE_WEBSOCKET
 }
 
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index 75477bf..74dc0dd 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -234,9 +234,9 @@
       return false;
     }
 
-  throw ConfigFile::Error("Invalid value for option \"" +
-                          optionName + "\" in \"" +
-                          sectionName + "\" section");
+   BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"" +
+                                           optionName + "\" in \"" +
+                                           sectionName + "\" section"));
 }
 
 inline void
diff --git a/daemon/mgmt/general-config-section.cpp b/daemon/mgmt/general-config-section.cpp
index 4064548..ce58909 100644
--- a/daemon/mgmt/general-config-section.cpp
+++ b/daemon/mgmt/general-config-section.cpp
@@ -73,14 +73,14 @@
 
       if (value.empty())
         {
-          throw ConfigFile::Error("Invalid value for \"router_name." + key + "\""
-                                  " in \"general\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"router_name." + key + "\""
+                                                  " in \"general\" section"));
         }
     }
   catch (const boost::property_tree::ptree_error& error)
     {
-      throw ConfigFile::Error("Invalid value for \"router_name." + key + "\""
-                              " in \"general\" section");
+      BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"router_name." + key + "\""
+                                              " in \"general\" section"));
     }
 
   return value;
@@ -129,14 +129,14 @@
 
               if (user.empty())
                 {
-                  throw ConfigFile::Error("Invalid value for \"user\""
-                                          " in \"general\" section");
+                  BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"user\""
+                                                          " in \"general\" section"));
                 }
             }
           catch (const boost::property_tree::ptree_error& error)
             {
-              throw ConfigFile::Error("Invalid value for \"user\""
-                                      " in \"general\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"user\""
+                                                      " in \"general\" section"));
             }
         }
       else if (i->first == "group")
@@ -147,14 +147,14 @@
 
               if (group.empty())
                 {
-                  throw ConfigFile::Error("Invalid value for \"group\""
-                                          " in \"general\" section");
+                  BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"group\""
+                                                          " in \"general\" section"));
                 }
             }
           catch (const boost::property_tree::ptree_error& error)
             {
-              throw ConfigFile::Error("Invalid value for \"group\""
-                                      " in \"general\" section");
+              BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for \"group\""
+                                                      " in \"general\" section"));
             }
         }
     }
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
index ec142ef..7569fb9 100644
--- a/daemon/mgmt/internal-face.cpp
+++ b/daemon/mgmt/internal-face.cpp
@@ -128,7 +128,7 @@
 void
 InternalFace::close()
 {
-  throw Error("Internal face cannot be closed");
+  BOOST_THROW_EXCEPTION(Error("Internal face cannot be closed"));
 }
 
 void
diff --git a/daemon/mgmt/tables-config-section.cpp b/daemon/mgmt/tables-config-section.cpp
index 861ed7f..c7661ce 100644
--- a/daemon/mgmt/tables-config-section.cpp
+++ b/daemon/mgmt/tables-config-section.cpp
@@ -102,8 +102,8 @@
 
       if (!valCsMaxPackets)
         {
-          throw ConfigFile::Error("Invalid value for option \"cs_max_packets\""
-                                  " in \"tables\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid value for option \"cs_max_packets\""
+                                                  " in \"tables\" section"));
         }
 
       nCsMaxPackets = *valCsMaxPackets;
@@ -145,23 +145,26 @@
       const Name prefix(prefixAndStrategy.first);
       if (choices.find(prefix) != choices.end())
         {
-          throw ConfigFile::Error("Duplicate strategy choice for prefix \"" +
-                                  prefix.toUri() + "\" in \"strategy_choice\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Duplicate strategy choice for prefix \"" +
+                                                  prefix.toUri() + "\" in \"strategy_choice\" "
+                                                  "section"));
         }
 
       const std::string strategyString(prefixAndStrategy.second.get_value<std::string>());
       if (strategyString.empty())
         {
-          throw ConfigFile::Error("Invalid strategy choice \"\" for prefix \"" +
-                                  prefix.toUri() + "\" in \"strategy_choice\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid strategy choice \"\" for prefix \"" +
+                                                  prefix.toUri() + "\" in \"strategy_choice\" "
+                                                  "section"));
         }
 
       const Name strategyName(strategyString);
       if (!m_strategyChoice.hasStrategy(strategyName))
         {
-          throw ConfigFile::Error("Invalid strategy choice \"" +
-                                  strategyName.toUri() + "\" for prefix \"" +
-                                  prefix.toUri() + "\" in \"strategy_choice\" section");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid strategy choice \"" +
+                                                  strategyName.toUri() + "\" for prefix \"" +
+                                                  prefix.toUri() + "\" in \"strategy_choice\" "
+                                                  "section"));
         }
 
       choices[prefix] = strategyName;
@@ -172,9 +175,10 @@
     {
       if (!isDryRun && !m_strategyChoice.insert(prefixAndStrategy.first, prefixAndStrategy.second))
         {
-          throw ConfigFile::Error("Failed to set strategy \"" +
-                                  prefixAndStrategy.second.toUri() + "\" for prefix \"" +
-                                  prefixAndStrategy.first.toUri() + "\" in \"strategy_choicev\"");
+          BOOST_THROW_EXCEPTION(ConfigFile::Error("Failed to set strategy \"" +
+                                                  prefixAndStrategy.second.toUri() + "\" for "
+                                                  "prefix \"" + prefixAndStrategy.first.toUri() +
+                                                  "\" in \"strategy_choicev\""));
         }
     }
 }