Replace exit()s with exceptions

This commit is contained in:
Alexey Rybalchenko
2020-05-17 13:58:24 +02:00
parent 4b516de81a
commit b56e32eb11
4 changed files with 30 additions and 26 deletions

View File

@@ -9,6 +9,8 @@
#ifndef FAIR_MQ_ZMQ_POLLER_H
#define FAIR_MQ_ZMQ_POLLER_H
#include <fairmq/zeromq/Socket.h>
#include <fairmq/Tools.h>
#include <FairMQChannel.h>
#include <FairMQLogger.h>
#include <FairMQPoller.h>
@@ -104,8 +106,8 @@ class Poller final : public fair::mq::Poller
}
} catch (const std::out_of_range& oor) {
LOG(error) << "at least one of the provided channel keys for poller initialization is invalid";
LOG(error) << "out of range error: " << oor.what() << '\n';
throw std::out_of_range("invalid channel during poller initialization");
LOG(error) << "out of range error: " << oor.what();
throw fair::mq::PollerError(fair::mq::tools::ToString("At least one of the provided channel keys for poller initialization is invalid. ", "Out of range error: ", oor.what()));
}
}
@@ -122,7 +124,7 @@ class Poller final : public fair::mq::Poller
item.events = ZMQ_POLLIN;
} else {
LOG(error) << "invalid poller configuration, exiting.";
exit(EXIT_FAILURE);
throw fair::mq::PollerError("Invalid poller configuration, exiting.");
}
}
@@ -133,7 +135,7 @@ class Poller final : public fair::mq::Poller
LOG(debug) << "polling exited, reason: " << zmq_strerror(errno);
} else {
LOG(error) << "polling failed, reason: " << zmq_strerror(errno);
throw std::runtime_error("polling failed");
throw fair::mq::PollerError(fair::mq::tools::ToString("Polling failed, reason: ", zmq_strerror(errno)));
}
}
}
@@ -165,9 +167,9 @@ class Poller final : public fair::mq::Poller
return false;
} catch (const std::out_of_range& oor) {
LOG(error) << "invalid channel key: \"" << channelKey << "\"";
LOG(error) << "out of range error: " << oor.what() << '\n';
exit(EXIT_FAILURE);
LOG(error) << "invalid channel key: '" << channelKey << "'";
LOG(error) << "out of range error: " << oor.what();
throw fair::mq::PollerError(fair::mq::tools::ToString("Invalid channel key '", channelKey, "'. Out of range error: ", oor.what()));
}
}
@@ -180,9 +182,9 @@ class Poller final : public fair::mq::Poller
return false;
} catch (const std::out_of_range& oor) {
LOG(error) << "invalid channel key: \"" << channelKey << "\"";
LOG(error) << "out of range error: " << oor.what() << '\n';
exit(EXIT_FAILURE);
LOG(error) << "invalid channel key: '" << channelKey << "'";
LOG(error) << "out of range error: " << oor.what();
throw fair::mq::PollerError(fair::mq::tools::ToString("Invalid channel key '", channelKey, "'. Out of range error: ", oor.what()));
}
}

View File

@@ -40,7 +40,7 @@ class Socket final : public fair::mq::Socket
{
if (fSocket == nullptr) {
LOG(error) << "Failed creating socket " << fId << ", reason: " << zmq_strerror(errno);
exit(EXIT_FAILURE);
throw SocketError(tools::ToString("Unavailable transport requested: ", type));
}
if (zmq_setsockopt(fSocket, ZMQ_IDENTITY, fId.c_str(), fId.length()) != 0) {