Enhance exception throwing with Boost Exception library

Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/lp/cache-policy.cpp b/src/lp/cache-policy.cpp
index 6bd1be9..2802b96 100644
--- a/src/lp/cache-policy.cpp
+++ b/src/lp/cache-policy.cpp
@@ -56,7 +56,7 @@
 CachePolicy::wireEncode(EncodingImpl<TAG>& encoder) const
 {
   if (m_policy == CachePolicyType::NONE) {
-    throw Error("CachePolicyType must be set");
+    BOOST_THROW_EXCEPTION(Error("CachePolicyType must be set"));
   }
   size_t length = 0;
   length += prependNonNegativeIntegerBlock(encoder, tlv::CachePolicyType,
@@ -76,7 +76,7 @@
 CachePolicy::wireEncode() const
 {
   if (m_policy == CachePolicyType::NONE) {
-    throw Error("CachePolicyType must be set");
+    BOOST_THROW_EXCEPTION(Error("CachePolicyType must be set"));
   }
 
   if (m_wire.hasWire()) {
@@ -98,7 +98,7 @@
 CachePolicy::wireDecode(const Block& wire)
 {
   if (wire.type() != tlv::CachePolicy) {
-    throw Error("expecting CachePolicy block");
+    BOOST_THROW_EXCEPTION(Error("expecting CachePolicy block"));
   }
 
   m_wire = wire;
@@ -108,11 +108,11 @@
   if (it != m_wire.elements_end() && it->type() == tlv::CachePolicyType) {
     m_policy = static_cast<CachePolicyType>(readNonNegativeInteger(*it));
     if (this->getPolicy() == CachePolicyType::NONE) {
-      throw Error("unknown CachePolicyType");
+      BOOST_THROW_EXCEPTION(Error("unknown CachePolicyType"));
     }
   }
   else {
-    throw Error("expecting CachePolicyType block");
+    BOOST_THROW_EXCEPTION(Error("expecting CachePolicyType block"));
   }
 }
 
diff --git a/src/lp/detail/field-decl.hpp b/src/lp/detail/field-decl.hpp
index e6fd4aa..0738768 100644
--- a/src/lp/detail/field-decl.hpp
+++ b/src/lp/detail/field-decl.hpp
@@ -44,7 +44,7 @@
   decode(const Block& wire)
   {
     if (wire.type() != TlvType::value) {
-      throw ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type()));
+      BOOST_THROW_EXCEPTION(ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type())));
     }
 
     T type;
@@ -60,7 +60,7 @@
   decode(const Block& wire)
   {
     if (wire.type() != TlvType::value) {
-      throw ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type()));
+      BOOST_THROW_EXCEPTION(ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type())));
     }
 
     return readNonNegativeInteger(wire);
@@ -74,11 +74,11 @@
   decode(const Block& wire)
   {
     if (wire.type() != TlvType::value) {
-      throw ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type()));
+      BOOST_THROW_EXCEPTION(ndn::tlv::Error("Unexpected TLV type " + std::to_string(wire.type())));
     }
 
     if (wire.value_size() == 0) {
-      throw ndn::tlv::Error(std::to_string(wire.type()) + " must not be empty");
+      BOOST_THROW_EXCEPTION(ndn::tlv::Error(std::to_string(wire.type()) + " must not be empty"));
     }
 
     return std::make_pair(wire.value_begin(), wire.value_end());
@@ -147,4 +147,4 @@
 } // namespace lp
 } // namesapce ndn
 
-#endif // NDN_CXX_LP_DETAIL_FIELD_DECL_HPP
\ No newline at end of file
+#endif // NDN_CXX_LP_DETAIL_FIELD_DECL_HPP
diff --git a/src/lp/nack-header.cpp b/src/lp/nack-header.cpp
index 22fccae..9f3157c 100644
--- a/src/lp/nack-header.cpp
+++ b/src/lp/nack-header.cpp
@@ -96,7 +96,7 @@
 NackHeader::wireDecode(const Block& wire)
 {
   if (wire.type() != tlv::Nack) {
-    throw ndn::tlv::Error("expecting Nack block");
+    BOOST_THROW_EXCEPTION(ndn::tlv::Error("expecting Nack block"));
   }
 
   m_wire = wire;
@@ -110,7 +110,7 @@
       m_reason = static_cast<NackReason>(readNonNegativeInteger(*it));
     }
     else {
-      throw ndn::tlv::Error("expecting NackReason block");
+      BOOST_THROW_EXCEPTION(ndn::tlv::Error("expecting NackReason block"));
     }
   }
 }
diff --git a/src/lp/packet.cpp b/src/lp/packet.cpp
index 20de690..67957af 100644
--- a/src/lp/packet.cpp
+++ b/src/lp/packet.cpp
@@ -97,16 +97,16 @@
     detail::FieldInfo info(element.type());
 
     if (!info.isRecognized && !info.canIgnore) {
-      throw Error("unknown field cannot be ignored");
+      BOOST_THROW_EXCEPTION(Error("unknown field cannot be ignored"));
     }
 
     if (!isFirst) {
       if (info.tlvType == prev.tlvType && !info.isRepeatable) {
-        throw Error("non-repeatable field cannot be repeated");
+        BOOST_THROW_EXCEPTION(Error("non-repeatable field cannot be repeated"));
       }
 
       else if (info.tlvType != prev.tlvType && !detail::compareFieldSortOrder(prev, info)) {
-        throw Error("fields are not in correct sort order");
+        BOOST_THROW_EXCEPTION(Error("fields are not in correct sort order"));
       }
     }
 
@@ -126,4 +126,4 @@
 }
 
 } // namespace lp
-} // namespace ndn
\ No newline at end of file
+} // namespace ndn
diff --git a/src/lp/packet.hpp b/src/lp/packet.hpp
index bf0cb01..0febb75 100644
--- a/src/lp/packet.hpp
+++ b/src/lp/packet.hpp
@@ -110,7 +110,7 @@
       }
     }
 
-    throw std::out_of_range("Index out of range");
+    BOOST_THROW_EXCEPTION(std::out_of_range("Index out of range"));
   }
 
   /**
@@ -155,7 +155,7 @@
   add(const typename FIELD::ValueType& value)
   {
     if (!FIELD::IsRepeatable::value && has<FIELD>()) {
-      throw std::length_error("Field cannot be repeated");
+      BOOST_THROW_EXCEPTION(std::length_error("Field cannot be repeated"));
     }
 
     EncodingEstimator estimator;
@@ -195,7 +195,7 @@
       }
     }
 
-    throw std::out_of_range("Index out of range");
+    BOOST_THROW_EXCEPTION(std::out_of_range("Index out of range"));
   }
 
   /**
@@ -221,4 +221,4 @@
 } // namespace lp
 } // namespace ndn
 
-#endif // NDN_CXX_LP_PACKET_HPP
\ No newline at end of file
+#endif // NDN_CXX_LP_PACKET_HPP