diff --git a/main/gui/source/crash_handlers.cpp b/main/gui/source/crash_handlers.cpp index 567e10950..642402f5a 100644 --- a/main/gui/source/crash_handlers.cpp +++ b/main/gui/source/crash_handlers.cpp @@ -179,18 +179,18 @@ namespace hex::crash { // Print the current exception info try { - if (std::uncaught_exceptions() > 0) - std::rethrow_exception(std::current_exception()); + if (auto exception = std::current_exception(); exception != nullptr) + std::rethrow_exception(exception); else - log::fatal("std::terminate() called without an active exception"); + log::fatal("Program terminated due to unknown reason!"); } catch (std::exception &ex) { std::string exceptionStr = fmt::format("{}()::what() -> {}", trace::demangle(typeid(ex).name()), ex.what()); handleCrash(exceptionStr); log::fatal("Program terminated with uncaught exception: {}", exceptionStr); - } - triggerSafeShutdown(); + triggerSafeShutdown(); + } } // Setup functions to handle signals, uncaught exception, or similar stuff that will crash ImHex diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 49ed57a28..dfb0246f1 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -274,8 +274,12 @@ namespace hex::init { // Run all exit tasks, and print to console void runExitTasks() { for (const auto &[name, task, async, running] : init::getExitTasks()) { - const bool result = task(); - log::info("Exit task '{0}' finished {1}", name, result ? "successfully" : "unsuccessfully"); + try { + const bool result = task(); + log::info("Exit task '{0}' finished {1}", name, result ? "successfully" : "unsuccessfully"); + } catch (const std::exception &e) { + log::error("Exit task '{}' failed with exception: {}", name, e.what()); + } } }