mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
fix: Handle uncaught exceptions more gracefully
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user