From 9f724f0c0d9c06da482dfdf78f2b9e4c7e31c55e Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 14 Mar 2019 17:09:44 +0100 Subject: [PATCH] using only sls exceptions --- .../multiSlsDetector/multiSlsDetector.cpp | 2 +- slsReceiverSoftware/src/DataProcessor.cpp | 3 ++- slsReceiverSoftware/src/DataStreamer.cpp | 3 ++- slsReceiverSoftware/src/Fifo.cpp | 3 ++- slsReceiverSoftware/src/Listener.cpp | 3 ++- slsReceiverSoftware/src/slsReceiver.cpp | 5 +++-- slsSupportLib/include/ZmqSocket.h | 20 ++++++++++--------- .../include/sls_detector_exceptions.h | 6 ++++++ 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 2bb767dfa..a46542c7d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -385,7 +385,7 @@ std::string multiSlsDetector::exec(const char *cmd) { std::string result = ""; FILE *pipe = popen(cmd, "r"); if (!pipe) { - throw std::exception(); + throw RuntimeError("Could not open pipe"); } try { while (!feof(pipe)) { diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 252d69dad..629a7bae7 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -14,6 +14,7 @@ #include "HDF5File.h" #endif #include "DataStreamer.h" +#include "sls_detector_exceptions.h" #include #include @@ -56,7 +57,7 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f, currentFrameIndex(0) { if(ThreadObject::CreateThread() == FAIL) - throw std::exception(); + throw sls::RuntimeError("Could not create processing thread"); FILE_LOG(logDEBUG) << "DataProcessor " << ind << " created"; diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 9ffc221d7..328c9a237 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -8,6 +8,7 @@ #include "GeneralData.h" #include "Fifo.h" #include "ZmqSocket.h" +#include "sls_detector_exceptions.h" #include #include @@ -35,7 +36,7 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, std::vector* r, completeBuffer(nullptr) { if(ThreadObject::CreateThread() == FAIL) - throw std::exception(); + throw sls::RuntimeError("Could not create streaming thread"); FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created"; diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index f36047513..74c90c7a3 100644 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -6,6 +6,7 @@ ***********************************************/ #include "Fifo.h" +#include "sls_detector_exceptions.h" #include #include @@ -23,7 +24,7 @@ Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth): status_fifoFree(depth){ FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; if(CreateFifos(fifoItemSize) == FAIL) - throw std::exception(); + throw sls::RuntimeError("Could not create FIFO"); } diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 8b548945a..c3461d7e6 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -11,6 +11,7 @@ #include "Fifo.h" #include "genericSocket.h" #include "container_utils.h" // For sls::make_unique<> +#include "sls_detector_exceptions.h" #include #include @@ -57,7 +58,7 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s, oddStartingPacket(true) { if(ThreadObject::CreateThread() == FAIL) - throw std::exception(); + throw sls::RuntimeError("Could not create listener thread"); FILE_LOG(logDEBUG) << "Listener " << ind << " created"; } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 112401dc6..73bea514c 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -15,6 +15,7 @@ #include "slsReceiver.h" #include "slsReceiverTCPIPInterface.h" +#include "sls_detector_exceptions.h" #include "gitInfoReceiver.h" #include "logger.h" @@ -60,7 +61,7 @@ slsReceiver::slsReceiver(int argc, char *argv[]): tempval = GITREV; tempval = (tempval <<32) | GITDATE; std::cout << "SLS Receiver " << GITBRANCH << " (0x" << std::hex << tempval << ")" << std::endl; - throw std::exception(); + throw sls::RuntimeError(); case 'h': default: @@ -73,7 +74,7 @@ slsReceiver::slsReceiver(int argc, char *argv[]): + "\t receivers\n\n"; FILE_LOG(logINFO) << help_message << std::endl; - throw std::exception(); + throw sls::RuntimeError(); } } diff --git a/slsSupportLib/include/ZmqSocket.h b/slsSupportLib/include/ZmqSocket.h index 9b422f2aa..68c3c0532 100644 --- a/slsSupportLib/include/ZmqSocket.h +++ b/slsSupportLib/include/ZmqSocket.h @@ -8,7 +8,7 @@ */ #include "ansi.h" - +#include "sls_detector_exceptions.h" #include #include @@ -27,6 +27,8 @@ using namespace rapidjson; // #define ZMQ_DETAIL #define ROIVERBOSITY + + class ZmqSocket { public: @@ -54,7 +56,7 @@ public: struct addrinfo *result; if ((ConvertHostnameToInternetAddress(hostname_or_ip, &result)) || (ConvertInternetAddresstoIpString(result, ip, MAX_STR_LENGTH))) - throw std::exception(); + throw sls::ZmqSocketError("Could convert IP to string"); // construct address sprintf (sockfd.serverAddress, "tcp://%s:%d", ip, portno); @@ -65,14 +67,14 @@ public: // create context sockfd.contextDescriptor = zmq_ctx_new(); if (sockfd.contextDescriptor == 0) - throw std::exception(); + throw sls::ZmqSocketError("Could not create contextDescriptor"); // create publisher sockfd.socketDescriptor = zmq_socket (sockfd.contextDescriptor, ZMQ_SUB); if (sockfd.socketDescriptor == 0) { PrintError (); Close (); - throw std::exception(); + throw sls::ZmqSocketError("Could not create socket"); } //Socket Options provided above @@ -80,7 +82,7 @@ public: if ( zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SUBSCRIBE, "", 0)) { PrintError (); Close(); - throw std::exception(); + throw sls::ZmqSocketError("Could set socket opt"); } //ZMQ_LINGER default is already -1 means no messages discarded. use this options if optimizing required //ZMQ_SNDHWM default is 0 means no limit. use this to optimize if optimizing required @@ -89,7 +91,7 @@ public: if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_LINGER, &value,sizeof(value))) { PrintError (); Close(); - throw std::exception(); + throw sls::ZmqSocketError("Could not set ZMQ_LINGER"); } }; @@ -110,13 +112,13 @@ public: // create context sockfd.contextDescriptor = zmq_ctx_new(); if (sockfd.contextDescriptor == 0) - throw std::exception(); + throw sls::ZmqSocketError("Could not create contextDescriptor"); // create publisher sockfd.socketDescriptor = zmq_socket (sockfd.contextDescriptor, ZMQ_PUB); if (sockfd.socketDescriptor == 0) { PrintError (); Close (); - throw std::exception(); + throw sls::ZmqSocketError("Could not create socket"); } //Socket Options provided above @@ -130,7 +132,7 @@ public: if (zmq_bind (sockfd.socketDescriptor, sockfd.serverAddress) < 0) { PrintError (); Close (); - throw std::exception(); + throw sls::ZmqSocketError("Could not bind socket"); } //sleep for a few milliseconds to allow a slow-joiner diff --git a/slsSupportLib/include/sls_detector_exceptions.h b/slsSupportLib/include/sls_detector_exceptions.h index 2c49e1bd9..8819d9911 100644 --- a/slsSupportLib/include/sls_detector_exceptions.h +++ b/slsSupportLib/include/sls_detector_exceptions.h @@ -30,6 +30,12 @@ public: }; +struct ZmqSocketError : public RuntimeError { +public: + ZmqSocketError(std::string msg):RuntimeError(msg) {} + +}; + }