Catch `boost::exception`s
This commit is contained in:
parent
9b6be51dd3
commit
9acd10fa4c
18
cli/main.cpp
18
cli/main.cpp
|
@ -31,6 +31,9 @@
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/exception/diagnostic_information.hpp>
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -601,6 +604,21 @@ int main(int argc, const char *argv[])
|
||||||
std::bind(&handleResponse, std::ref(url), std::placeholders::_1, std::placeholders::_2, rawArg.isPresent() ? printRawData : printer,
|
std::bind(&handleResponse, std::ref(url), std::placeholders::_1, std::placeholders::_2, rawArg.isPresent() ? printRawData : printer,
|
||||||
std::ref(returnCode)),
|
std::ref(returnCode)),
|
||||||
std::string(), config.userName, config.password, verb, std::nullopt, chunkHandler);
|
std::string(), config.userName, config.password, verb, std::nullopt, chunkHandler);
|
||||||
|
#ifndef CPP_UTILITIES_DEBUG_BUILD
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
ioContext.run();
|
ioContext.run();
|
||||||
|
#ifndef CPP_UTILITIES_DEBUG_BUILD
|
||||||
|
} catch (const boost::exception &e) {
|
||||||
|
cerr << Phrases::ErrorMessage << "Unhandled exception: " << Phrases::End << " " << boost::diagnostic_information(e) << Phrases::EndFlush;
|
||||||
|
return -3;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
cerr << Phrases::ErrorMessage << "Unhandled exception: " << Phrases::End << " " << e.what() << Phrases::EndFlush;
|
||||||
|
return -3;
|
||||||
|
} catch (...) {
|
||||||
|
cerr << Phrases::ErrorMessage << "Terminated due to unknown error." << Phrases::EndFlush;
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include <boost/asio/ssl/error.hpp>
|
#include <boost/asio/ssl/error.hpp>
|
||||||
#include <boost/asio/ssl/stream.hpp>
|
#include <boost/asio/ssl/stream.hpp>
|
||||||
|
|
||||||
|
#include <boost/exception/diagnostic_information.hpp>
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
|
|
||||||
#ifdef PLATFORM_LINUX
|
#ifdef PLATFORM_LINUX
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -686,6 +689,10 @@ int ServiceSetup::run()
|
||||||
WebAPI::Server::serve(*this);
|
WebAPI::Server::serve(*this);
|
||||||
cout << Phrases::SuccessMessage << "Web server stopped." << Phrases::EndFlush;
|
cout << Phrases::SuccessMessage << "Web server stopped." << Phrases::EndFlush;
|
||||||
#ifndef CPP_UTILITIES_DEBUG_BUILD
|
#ifndef CPP_UTILITIES_DEBUG_BUILD
|
||||||
|
} catch (const boost::exception &e) {
|
||||||
|
cerr << Phrases::ErrorMessage << "Server terminated due to exception: " << Phrases::End << " " << boost::diagnostic_information(e)
|
||||||
|
<< Phrases::EndFlush;
|
||||||
|
return -3;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
cerr << Phrases::ErrorMessage << "Server terminated due to exception: " << Phrases::End << " " << e.what() << Phrases::EndFlush;
|
cerr << Phrases::ErrorMessage << "Server terminated due to exception: " << Phrases::End << " " << e.what() << Phrases::EndFlush;
|
||||||
return -3;
|
return -3;
|
||||||
|
|
Loading…
Reference in New Issue