diff --git a/cli/main.cpp b/cli/main.cpp index 137f214..4b4d83f 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -31,6 +31,9 @@ #pragma GCC diagnostic pop #endif +#include +#include + #include #include #include @@ -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::ref(returnCode)), std::string(), config.userName, config.password, verb, std::nullopt, chunkHandler); - ioContext.run(); +#ifndef CPP_UTILITIES_DEBUG_BUILD + try { +#endif + 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; } diff --git a/librepomgr/serversetup.cpp b/librepomgr/serversetup.cpp index 1b2b047..8004d6f 100644 --- a/librepomgr/serversetup.cpp +++ b/librepomgr/serversetup.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + #ifdef PLATFORM_LINUX #include #endif @@ -686,6 +689,10 @@ int ServiceSetup::run() WebAPI::Server::serve(*this); cout << Phrases::SuccessMessage << "Web server stopped." << Phrases::EndFlush; #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) { cerr << Phrases::ErrorMessage << "Server terminated due to exception: " << Phrases::End << " " << e.what() << Phrases::EndFlush; return -3;