Enhance exception throwing with Boost Exception library
Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4962ba
Refs: #2997
diff --git a/src/transport/stream-transport.hpp b/src/transport/stream-transport.hpp
index d7f2e49..99dc510 100644
--- a/src/transport/stream-transport.hpp
+++ b/src/transport/stream-transport.hpp
@@ -68,7 +68,7 @@
// may need to throw exception
m_transport.m_isConnected = false;
m_transport.close();
- throw Transport::Error(error, "error while connecting to the forwarder");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "error while connecting to the forwarder"));
}
}
@@ -79,7 +79,7 @@
return;
m_transport.close();
- throw Transport::Error(error, "error while connecting to the forwarder");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "error while connecting to the forwarder"));
}
void
@@ -192,7 +192,7 @@
}
m_transport.close();
- throw Transport::Error(error, "error while sending data to socket");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "error while sending data to socket"));
}
m_transmissionQueue.erase(queueItem);
@@ -231,7 +231,7 @@
}
m_transport.close();
- throw Transport::Error(error, "error while receiving data from socket");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "error while receiving data from socket"));
}
m_inputBufferSize += nBytesRecvd;
@@ -242,8 +242,9 @@
if (!hasProcessedSome && m_inputBufferSize == MAX_NDN_PACKET_SIZE && offset == 0)
{
m_transport.close();
- throw Transport::Error(boost::system::error_code(),
- "input buffer full, but a valid TLV cannot be decoded");
+ BOOST_THROW_EXCEPTION(Transport::Error(boost::system::error_code(),
+ "input buffer full, but a valid TLV cannot be "
+ "decoded"));
}
if (offset > 0)
@@ -300,14 +301,14 @@
if (error == boost::system::errc::operation_canceled)
return;
- throw Transport::Error(error, "Error during resolution of host or port");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "Error during resolution of host or port"));
}
typename Protocol::resolver::iterator end;
if (endpoint == end)
{
this->m_transport.close();
- throw Transport::Error(error, "Unable to resolve because host or port");
+ BOOST_THROW_EXCEPTION(Transport::Error(error, "Unable to resolve because host or port"));
}
this->m_socket.async_connect(*endpoint,
diff --git a/src/transport/tcp-transport.cpp b/src/transport/tcp-transport.cpp
index c43790f..afde1e0 100644
--- a/src/transport/tcp-transport.cpp
+++ b/src/transport/tcp-transport.cpp
@@ -57,8 +57,8 @@
const std::string scheme = uri.getScheme();
if (scheme != "tcp" && scheme != "tcp4" && scheme != "tcp6") {
- throw Transport::Error("Cannot create TcpTransport from \"" +
- scheme + "\" URI");
+ BOOST_THROW_EXCEPTION(Transport::Error("Cannot create TcpTransport from \"" +
+ scheme + "\" URI"));
}
if (!uri.getHost().empty()) {
@@ -70,7 +70,7 @@
}
}
catch (const util::FaceUri::Error& error) {
- throw ConfigFile::Error(error.what());
+ BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
}
return {host, port};
diff --git a/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
index df505d7..3464d79 100644
--- a/src/transport/unix-transport.cpp
+++ b/src/transport/unix-transport.cpp
@@ -49,8 +49,8 @@
if (uri.getScheme() != "unix")
{
- throw Transport::Error("Cannot create UnixTransport from \"" +
- uri.getScheme() + "\" URI");
+ BOOST_THROW_EXCEPTION(Transport::Error("Cannot create UnixTransport from \"" +
+ uri.getScheme() + "\" URI"));
}
if (!uri.getPath().empty())
@@ -64,11 +64,11 @@
}
catch (const boost::property_tree::ptree_bad_data& error)
{
- throw ConfigFile::Error(error.what());
+ BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
}
catch (const util::FaceUri::Error& error)
{
- throw ConfigFile::Error(error.what());
+ BOOST_THROW_EXCEPTION(ConfigFile::Error(error.what()));
}
// Assume the default nfd.sock location.