Enhance exception throwing with Boost Exception library
Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 77be4f2..624439d 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -63,7 +63,7 @@
uint64_t length = tlv::readVarNumber(m_value_begin, m_value_end);
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw tlv::Error("TLV length doesn't match buffer length");
+ BOOST_THROW_EXCEPTION(tlv::Error("TLV length doesn't match buffer length"));
}
}
@@ -95,7 +95,7 @@
uint64_t length = tlv::readVarNumber(m_value_begin, m_value_end);
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw tlv::Error("TLV length doesn't match buffer length");
+ BOOST_THROW_EXCEPTION(tlv::Error("TLV length doesn't match buffer length"));
}
}
@@ -116,7 +116,7 @@
{
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw tlv::Error("TLV length doesn't match buffer length");
+ BOOST_THROW_EXCEPTION(tlv::Error("TLV length doesn't match buffer length"));
}
}
}
@@ -131,7 +131,7 @@
if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
{
- throw tlv::Error("Not enough data in the buffer to fully parse TLV");
+ BOOST_THROW_EXCEPTION(tlv::Error("Not enough data in the buffer to fully parse TLV"));
}
m_buffer = make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
@@ -156,7 +156,7 @@
if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
{
- throw tlv::Error("Not enough data in the buffer to fully parse TLV");
+ BOOST_THROW_EXCEPTION(tlv::Error("Not enough data in the buffer to fully parse TLV"));
}
m_buffer = make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
@@ -210,7 +210,7 @@
}
if (length > MAX_SIZE_OF_BLOCK_FROM_STREAM)
- throw tlv::Error("Length of block from stream is too large");
+ BOOST_THROW_EXCEPTION(tlv::Error("Length of block from stream is too large"));
// We may still have some problem here, if some exception happens,
// we may completely lose all the bytes extracted from the stream.
@@ -220,7 +220,7 @@
is.read(buf + 1, length - 1);
if (length != static_cast<uint64_t>(is.gcount()) + 1) {
- throw tlv::Error("Not enough data in the buffer to fully parse TLV");
+ BOOST_THROW_EXCEPTION(tlv::Error("Not enough data in the buffer to fully parse TLV"));
}
return makeBinaryBlock(type, buf, length);
@@ -314,7 +314,7 @@
if (length > static_cast<uint64_t>(end - begin))
{
m_subBlocks.clear();
- throw tlv::Error("TLV length exceeds buffer length");
+ BOOST_THROW_EXCEPTION(tlv::Error("TLV length exceeds buffer length"));
}
Buffer::const_iterator element_end = begin + length;
@@ -364,7 +364,7 @@
os.write(reinterpret_cast<const char*>(i->value()), i->value_size());
}
else
- throw Error("Underlying value buffer is empty");
+ BOOST_THROW_EXCEPTION(Error("Underlying value buffer is empty"));
}
}
@@ -389,8 +389,8 @@
if (it != m_subBlocks.end())
return *it;
- throw Error("(Block::get) Requested a non-existed type [" +
- boost::lexical_cast<std::string>(type) + "] from Block");
+ BOOST_THROW_EXCEPTION(Error("(Block::get) Requested a non-existed type [" +
+ boost::lexical_cast<std::string>(type) + "] from Block"));
}
Block::element_const_iterator
@@ -414,7 +414,7 @@
Block::blockFromValue() const
{
if (value_size() == 0)
- throw Error("Underlying value buffer is empty");
+ BOOST_THROW_EXCEPTION(Error("Underlying value buffer is empty"));
Buffer::const_iterator begin = value_begin(),
end = value_end();
@@ -425,7 +425,7 @@
uint64_t length = tlv::readVarNumber(begin, end);
if (length != static_cast<uint64_t>(end - begin))
- throw tlv::Error("TLV length mismatches buffer length");
+ BOOST_THROW_EXCEPTION(tlv::Error("TLV length mismatches buffer length"));
return Block(m_buffer,
type,
@@ -454,7 +454,7 @@
Block::begin() const
{
if (!hasWire())
- throw Error("Underlying wire buffer is empty");
+ BOOST_THROW_EXCEPTION(Error("Underlying wire buffer is empty"));
return m_begin;
}
@@ -463,7 +463,7 @@
Block::end() const
{
if (!hasWire())
- throw Error("Underlying wire buffer is empty");
+ BOOST_THROW_EXCEPTION(Error("Underlying wire buffer is empty"));
return m_end;
}
@@ -472,7 +472,7 @@
Block::wire() const
{
if (!hasWire())
- throw Error("(Block::wire) Underlying wire buffer is empty");
+ BOOST_THROW_EXCEPTION(Error("(Block::wire) Underlying wire buffer is empty"));
return &*m_begin;
}
@@ -484,7 +484,7 @@
return m_size;
}
else
- throw Error("Block size cannot be determined (undefined block size)");
+ BOOST_THROW_EXCEPTION(Error("Block size cannot be determined (undefined block size)"));
}
bool
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 7d7461f..b1223e8 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -303,12 +303,12 @@
readVarNumber(InputIterator& begin, const InputIterator& end)
{
if (begin == end)
- throw Error("Empty buffer during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Empty buffer during TLV processing"));
uint64_t value;
bool isOk = readVarNumber(begin, end, value);
if (!isOk)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
return value;
}
@@ -378,7 +378,7 @@
uint64_t type = readVarNumber(begin, end);
if (type > std::numeric_limits<uint32_t>::max())
{
- throw Error("TLV type code exceeds allowed maximum");
+ BOOST_THROW_EXCEPTION(Error("TLV type code exceeds allowed maximum"));
}
return static_cast<uint32_t>(type);
@@ -436,7 +436,7 @@
case 1:
{
if (end - begin < 1)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
uint8_t value = *begin;
begin++;
@@ -445,7 +445,7 @@
case 2:
{
if (end - begin < 2)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
uint16_t value = *reinterpret_cast<const uint16_t*>(&*begin);
begin += 2;
@@ -454,7 +454,7 @@
case 4:
{
if (end - begin < 4)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
uint32_t value = *reinterpret_cast<const uint32_t*>(&*begin);
begin += 4;
@@ -463,14 +463,14 @@
case 8:
{
if (end - begin < 8)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
uint64_t value = *reinterpret_cast<const uint64_t*>(&*begin);
begin += 8;
return be64toh(value);
}
}
- throw Error("Invalid length for nonNegativeInteger (only 1, 2, 4, and 8 are allowed)");
+ BOOST_THROW_EXCEPTION(Error("Invalid length for nonNegativeInteger (only 1, 2, 4, and 8 are allowed)"));
}
template<>
@@ -483,7 +483,7 @@
case 1:
{
if (begin == end)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
uint64_t value = *begin;
begin++;
@@ -500,7 +500,7 @@
}
if (count != 2)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
return value;
}
@@ -515,7 +515,7 @@
}
if (count != 4)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
return value;
}
@@ -530,12 +530,12 @@
}
if (count != 8)
- throw Error("Insufficient data during TLV processing");
+ BOOST_THROW_EXCEPTION(Error("Insufficient data during TLV processing"));
return value;
}
}
- throw Error("Invalid length for nonNegativeInteger (only 1, 2, 4, and 8 are allowed)");
+ BOOST_THROW_EXCEPTION(Error("Invalid length for nonNegativeInteger (only 1, 2, 4, and 8 are allowed)"));
}
inline size_t