Enhance exception throwing with Boost Exception library
Change-Id: I471023fc23ffaebe04d9668426b4c1b03e4919aa
Refs: #2541
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 856213c..f31a8f6 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -83,7 +83,7 @@
int fd = pcap_get_selectable_fd(m_pcap.get());
if (fd < 0)
- throw Error("pcap_get_selectable_fd failed");
+ BOOST_THROW_EXCEPTION(Error("pcap_get_selectable_fd failed"));
// need to duplicate the fd, otherwise both pcap_close()
// and stream_descriptor::close() will try to close the
@@ -165,7 +165,7 @@
char errbuf[PCAP_ERRBUF_SIZE] = {};
m_pcap.reset(pcap_create(m_interfaceName.c_str(), errbuf));
if (!m_pcap)
- throw Error("pcap_create: " + std::string(errbuf));
+ BOOST_THROW_EXCEPTION(Error("pcap_create: " + std::string(errbuf)));
#ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
// Enable "immediate mode", effectively disabling any read buffering in the kernel.
@@ -176,10 +176,10 @@
#endif
if (pcap_activate(m_pcap.get()) < 0)
- throw Error("pcap_activate failed");
+ BOOST_THROW_EXCEPTION(Error("pcap_activate failed"));
if (pcap_set_datalink(m_pcap.get(), DLT_EN10MB) < 0)
- throw Error("pcap_set_datalink: " + std::string(pcap_geterr(m_pcap.get())));
+ BOOST_THROW_EXCEPTION(Error("pcap_set_datalink: " + std::string(pcap_geterr(m_pcap.get()))));
if (pcap_setdirection(m_pcap.get(), PCAP_D_IN) < 0)
// no need to throw on failure, BPF will filter unwanted packets anyway
@@ -191,12 +191,12 @@
{
bpf_program filter;
if (pcap_compile(m_pcap.get(), &filter, filterString, 1, PCAP_NETMASK_UNKNOWN) < 0)
- throw Error("pcap_compile: " + std::string(pcap_geterr(m_pcap.get())));
+ BOOST_THROW_EXCEPTION(Error("pcap_compile: " + std::string(pcap_geterr(m_pcap.get()))));
int ret = pcap_setfilter(m_pcap.get(), &filter);
pcap_freecode(&filter);
if (ret < 0)
- throw Error("pcap_setfilter: " + std::string(pcap_geterr(m_pcap.get())));
+ BOOST_THROW_EXCEPTION(Error("pcap_setfilter: " + std::string(pcap_geterr(m_pcap.get()))));
}
bool
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index 9387fe6..63f428c 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -36,7 +36,7 @@
const ethernet::Address &address)
{
if (!address.isMulticast())
- throw Error(address.toString() + " is not a multicast address");
+ BOOST_THROW_EXCEPTION(Error(address.toString() + " is not a multicast address"));
shared_ptr<EthernetFace> face = findMulticastFace(interface.name, address);
if (face)
@@ -71,7 +71,7 @@
const FaceCreatedCallback& onCreated,
const FaceConnectFailedCallback& onConnectFailed)
{
- throw Error("EthernetFactory does not support 'createFace' operation");
+ BOOST_THROW_EXCEPTION(Error("EthernetFactory does not support 'createFace' operation"));
}
std::list<shared_ptr<const Channel>>
diff --git a/daemon/face/ndnlp-sequence-generator.hpp b/daemon/face/ndnlp-sequence-generator.hpp
index a3baa6b..3019933 100644
--- a/daemon/face/ndnlp-sequence-generator.hpp
+++ b/daemon/face/ndnlp-sequence-generator.hpp
@@ -54,7 +54,7 @@
SequenceBlock::operator[](size_t pos) const
{
if (pos >= m_count)
- throw std::out_of_range("pos");
+ BOOST_THROW_EXCEPTION(std::out_of_range("pos"));
return m_start + static_cast<uint64_t>(pos);
}
diff --git a/daemon/face/tcp-face.hpp b/daemon/face/tcp-face.hpp
index f77b72d..4313c06 100644
--- a/daemon/face/tcp-face.hpp
+++ b/daemon/face/tcp-face.hpp
@@ -69,7 +69,8 @@
if (!socket.local_endpoint().address().is_loopback() ||
!socket.remote_endpoint().address().is_loopback())
{
- throw Face::Error("TcpLocalFace can be created only on a loopback address");
+ BOOST_THROW_EXCEPTION(Face::Error("TcpLocalFace can be created only on a loopback "
+ "address"));
}
}
};
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 9c640a1..4fb6059 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -132,7 +132,7 @@
const FaceConnectFailedCallback& onConnectFailed)
{
if (persistency != ndn::nfd::FACE_PERSISTENCY_PERSISTENT) {
- throw Error("TcpFactory only supports persistent face");
+ BOOST_THROW_EXCEPTION(Error("TcpFactory only supports persistent face"));
}
BOOST_ASSERT(uri.isCanonical());
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 3a55b7c..07b0367 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -120,13 +120,13 @@
//checking if the endpoint is already in use for multicast face
shared_ptr<MulticastUdpFace> multicast = findMulticastFace(endpoint);
if (static_cast<bool>(multicast))
- throw Error("Cannot create the requested UDP unicast channel, local "
- "endpoint is already allocated for a UDP multicast face");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP unicast channel, local "
+ "endpoint is already allocated for a UDP multicast face"));
if (endpoint.address().is_multicast()) {
- throw Error("This method is only for unicast channel. The provided "
- "endpoint is multicast. Use createMulticastFace to "
- "create a multicast face");
+ BOOST_THROW_EXCEPTION(Error("This method is only for unicast channel. The provided "
+ "endpoint is multicast. Use createMulticastFace to "
+ "create a multicast face"));
}
channel = make_shared<UdpChannel>(endpoint, timeout);
@@ -157,35 +157,36 @@
if (face->getMulticastGroup() == multicastEndpoint)
return face;
else
- throw Error("Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP multicast face "
- "on a different multicast group");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, local "
+ "endpoint is already allocated for a UDP multicast face "
+ "on a different multicast group"));
}
// checking if the local endpoint is already in use for a unicast channel
shared_ptr<UdpChannel> unicast = findChannel(localEndpoint);
if (static_cast<bool>(unicast)) {
- throw Error("Cannot create the requested UDP multicast face, local "
- "endpoint is already allocated for a UDP unicast channel");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, local "
+ "endpoint is already allocated for a UDP unicast channel"));
}
if (m_prohibitedEndpoints.find(multicastEndpoint) != m_prohibitedEndpoints.end()) {
- throw Error("Cannot create the requested UDP multicast face, "
- "remote endpoint is owned by this NFD instance");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, "
+ "remote endpoint is owned by this NFD instance"));
}
if (localEndpoint.address().is_v6() || multicastEndpoint.address().is_v6()) {
- throw Error("IPv6 multicast is not supported yet. Please provide an IPv4 address");
+ BOOST_THROW_EXCEPTION(Error("IPv6 multicast is not supported yet. Please provide an IPv4 "
+ "address"));
}
if (localEndpoint.port() != multicastEndpoint.port()) {
- throw Error("Cannot create the requested UDP multicast face, "
- "both endpoints should have the same port number. ");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, "
+ "both endpoints should have the same port number. "));
}
if (!multicastEndpoint.address().is_multicast()) {
- throw Error("Cannot create the requested UDP multicast face, "
- "the multicast group given as input is not a multicast address");
+ BOOST_THROW_EXCEPTION(Error("Cannot create the requested UDP multicast face, "
+ "the multicast group given as input is not a multicast address"));
}
ip::udp::socket receiveSocket(getGlobalIoService());
@@ -218,8 +219,8 @@
if (!networkInterfaceName.empty()) {
if (::setsockopt(receiveSocket.native_handle(), SOL_SOCKET, SO_BINDTODEVICE,
networkInterfaceName.c_str(), networkInterfaceName.size() + 1) < 0) {
- throw Error("Cannot bind multicast face to " + networkInterfaceName +
- ": " + std::strerror(errno));
+ BOOST_THROW_EXCEPTION(Error("Cannot bind multicast face to " + networkInterfaceName +
+ ": " + std::strerror(errno)));
}
}
#endif
@@ -255,7 +256,7 @@
const FaceConnectFailedCallback& onConnectFailed)
{
if (persistency != ndn::nfd::FACE_PERSISTENCY_PERSISTENT) {
- throw Error("UdpFactory only supports persistent face");
+ BOOST_THROW_EXCEPTION(Error("UdpFactory only supports persistent face"));
}
BOOST_ASSERT(uri.isCanonical());
diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp
index ece6d0e..c883163 100644
--- a/daemon/face/unix-stream-channel.cpp
+++ b/daemon/face/unix-stream-channel.cpp
@@ -77,8 +77,8 @@
+ error.message());
if (!error) {
// someone answered, leave the socket alone
- throw Error("Socket file at " + m_endpoint.path()
- + " belongs to another NFD process");
+ BOOST_THROW_EXCEPTION(Error("Socket file at " + m_endpoint.path()
+ + " belongs to another NFD process"));
}
else if (error == boost::asio::error::connection_refused ||
error == boost::asio::error::timed_out) {
@@ -89,7 +89,7 @@
}
}
else if (type != fs::file_not_found) {
- throw Error(m_endpoint.path() + " already exists and is not a socket file");
+ BOOST_THROW_EXCEPTION(Error(m_endpoint.path() + " already exists and is not a socket file"));
}
m_acceptor.open();
@@ -97,7 +97,8 @@
m_acceptor.listen(backlog);
if (::chmod(m_endpoint.path().c_str(), 0666) < 0) {
- throw Error("chmod(" + m_endpoint.path() + ") failed: " + std::strerror(errno));
+ BOOST_THROW_EXCEPTION(Error("chmod(" + m_endpoint.path() + ") failed: " +
+ std::strerror(errno)));
}
// start accepting connections
diff --git a/daemon/face/unix-stream-factory.cpp b/daemon/face/unix-stream-factory.cpp
index 16a01a9..717f7b6 100644
--- a/daemon/face/unix-stream-factory.cpp
+++ b/daemon/face/unix-stream-factory.cpp
@@ -61,7 +61,7 @@
const FaceCreatedCallback& onCreated,
const FaceConnectFailedCallback& onConnectFailed)
{
- throw Error("UnixStreamFactory does not support 'createFace' operation");
+ BOOST_THROW_EXCEPTION(Error("UnixStreamFactory does not support 'createFace' operation"));
}
std::list<shared_ptr<const Channel> >
diff --git a/daemon/face/websocket-factory.cpp b/daemon/face/websocket-factory.cpp
index e911827..80e8efa 100644
--- a/daemon/face/websocket-factory.cpp
+++ b/daemon/face/websocket-factory.cpp
@@ -71,7 +71,7 @@
const FaceCreatedCallback& onCreated,
const FaceConnectFailedCallback& onConnectFailed)
{
- throw Error("WebSocketFactory does not support 'createFace' operation");
+ BOOST_THROW_EXCEPTION(Error("WebSocketFactory does not support 'createFace' operation"));
}
std::list<shared_ptr<const Channel> >