From 0977bc557d4df0d036da7760e039a41e45593563 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 23 Aug 2021 18:35:25 +0200 Subject: [PATCH] statusweather: Catch all exceptions. --- statusweather.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/statusweather.cpp b/statusweather.cpp index 72e077a..d4f30af 100644 --- a/statusweather.cpp +++ b/statusweather.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -193,19 +194,29 @@ void update(std::atomic &cancelled) int main() { - // TODO: Implement clean shutdown. - std::atomic cancelled{false}; - auto future{std::async(std::launch::async, update, std::ref(cancelled))}; - - std::string line; - while (std::getline(std::cin, line)) // Button click is sent to stdin. + try { - if (line == "1") // Left mouse button. + // TODO: Implement clean shutdown. + std::atomic cancelled{false}; + auto future{ + std::async(std::launch::async, update, std::ref(cancelled))}; + + std::string line; + while (std::getline(std::cin, line)) // Button click is sent to stdin. { - if (fetch_weather()) + if (line == "1") // Left mouse button. { - print_weather(); + if (fetch_weather()) + { + print_weather(); + } } } } + catch (std::exception &e) + { + std::cout << R"()" << e.what() << "" + << std::endl; + return 33; + } }