fix: Handle uncaught exceptions more gracefully

This commit is contained in:
WerWolv
2025-08-30 14:24:39 +02:00
parent a9d45d837f
commit e1079d751a
2 changed files with 11 additions and 7 deletions

View File

@@ -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

View File

@@ -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());
}
}
}