Add special handling for util::exception in various places to print stacktrace info

This commit is contained in:
Nikita Lisitsa 2023-08-06 12:53:03 +03:00
parent 1c22892eec
commit dd12ad9477
3 changed files with 18 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include <psemek/util/unused.hpp>
#include <psemek/util/to_string.hpp>
#include <psemek/util/exception.hpp>
#include <psemek/log/log.hpp>
@ -41,6 +42,10 @@ namespace psemek::async
{
running = false;
}
catch (util::exception const & e)
{
log::error() << "Unhandled exception in threadpool executor: " << e;
}
catch (std::exception const & e)
{
log::error() << "Unhandled exception in threadpool executor: " << e.what();

View file

@ -6,6 +6,7 @@
#include <psemek/util/clock.hpp>
#include <psemek/util/pretty_print.hpp>
#include <psemek/log/log.hpp>
#include <psemek/util/exception.hpp>
#undef main
@ -62,6 +63,11 @@ int main(int argc, char ** argv) try
log::info() << "Quitting";
return EXIT_SUCCESS;
}
catch (psemek::util::exception const & e)
{
psemek::log::error() << e;
return EXIT_FAILURE;
}
catch (std::exception const & e)
{
psemek::log::error() << e.what();

View file

@ -1,5 +1,6 @@
#include <psemek/test/test.hpp>
#include <psemek/util/pretty_print.hpp>
#include <psemek/util/exception.hpp>
#include <psemek/log/log.hpp>
#include <map>
@ -176,6 +177,12 @@ int main(int argc, char ** argv)
std::cout << indent << "Reason: " << yellow << e.message() << normal << std::endl;
std::cout << indent << "Location: " << cyan << e.location() << normal << std::endl;
}
catch (psemek::util::exception const & e)
{
auto end = clock::now();
std::cout << red << "failure: " << e.what() << normal << " " << psemek::util::pretty(end - start, std::chrono::milliseconds{1}) << std::endl;
std::cout << red << e.stacktrace();
}
catch (std::exception const & e)
{
auto end = clock::now();