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> >
diff --git a/daemon/main.cpp b/daemon/main.cpp
index e6b9ae7..6646240 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -240,10 +240,12 @@
po::variables_map vm;
try {
- po::store(po::command_line_parser(argc, argv).options(description).run(), vm);
- po::notify(vm);
+ po::store(po::command_line_parser(argc, argv).options(description).run(), vm);
+ po::notify(vm);
}
catch (const std::exception& e) {
+ // avoid NFD_LOG_FATAL to ensure that errors related to command-line parsing always appear on the
+ // terminal and are not littered with timestamps and other things added by the logging subsystem
std::cerr << "ERROR: " << e.what() << std::endl;
NfdRunner::printUsage(std::cerr, argv[0]);
return 1;
@@ -273,11 +275,12 @@
if (e.code() == boost::system::errc::permission_denied) {
NFD_LOG_FATAL("Permissions denied for " << e.path1() << ". " <<
argv[0] << " should be run as superuser");
+ return 3;
}
else {
NFD_LOG_FATAL(e.what());
+ return 2;
}
- return 1;
}
catch (const std::exception& e) {
NFD_LOG_FATAL(e.what());
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\""));
}
}
}
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index ceaa218..5df2482 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -51,7 +51,7 @@
, m_adjustCapacityInterval(m_lifetime)
{
if (m_lifetime < MIN_LIFETIME) {
- throw std::invalid_argument("lifetime is less than MIN_LIFETIME");
+ BOOST_THROW_EXCEPTION(std::invalid_argument("lifetime is less than MIN_LIFETIME"));
}
for (size_t i = 0; i < EXPECTED_MARK_COUNT; ++i) {