impr: Better unthrown exception error handling
This commit is contained in:
parent
81971eaf4a
commit
9baca91b16
@ -26,8 +26,8 @@ namespace hex::crash {
|
|||||||
hex::nativeErrorMessage(hex::format("ImHex crashed during its loading.\nError: {}", message));
|
hex::nativeErrorMessage(hex::format("ImHex crashed during its loading.\nError: {}", message));
|
||||||
}
|
}
|
||||||
|
|
||||||
// function that decides what should happen on a crash
|
// Function that decides what should happen on a crash
|
||||||
// (either sending a message or saving a crash file, depending on when the crash occured)
|
// (either sending a message or saving a crash file, depending on when the crash occurred)
|
||||||
static std::function<void(const std::string&)> crashCallback = sendNativeMessage;
|
static std::function<void(const std::string&)> crashCallback = sendNativeMessage;
|
||||||
|
|
||||||
static void saveCrashFile(const std::string& message) {
|
static void saveCrashFile(const std::string& message) {
|
||||||
@ -55,7 +55,7 @@ namespace hex::crash {
|
|||||||
static void signalHandler(int signalNumber, const std::string &signalName) {
|
static void signalHandler(int signalNumber, const std::string &signalName) {
|
||||||
log::fatal("Terminating with signal '{}' ({})", signalName, signalNumber);
|
log::fatal("Terminating with signal '{}' ({})", signalName, signalNumber);
|
||||||
|
|
||||||
// trigger the crash callback
|
// Trigger the crash callback
|
||||||
crashCallback(hex::format("Received signal '{}' ({})", signalName, signalNumber));
|
crashCallback(hex::format("Received signal '{}' ({})", signalName, signalNumber));
|
||||||
|
|
||||||
// Trigger an event so that plugins can handle crashes
|
// Trigger an event so that plugins can handle crashes
|
||||||
@ -87,7 +87,7 @@ namespace hex::crash {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup functions to handle signals, uncaught exception, or similar stuff that will crash ImHex
|
// Setup functions to handle signals, uncaught exception, or similar stuff that will crash ImHex
|
||||||
void setupCrashHandlers() {
|
void setupCrashHandlers() {
|
||||||
// Register signal handlers
|
// Register signal handlers
|
||||||
{
|
{
|
||||||
@ -113,21 +113,21 @@ namespace hex::crash {
|
|||||||
);
|
);
|
||||||
log::fatal("Program terminated with uncaught exception: {}", exceptionStr);
|
log::fatal("Program terminated with uncaught exception: {}", exceptionStr);
|
||||||
|
|
||||||
// handle crash callback
|
// Handle crash callback
|
||||||
crashCallback(hex::format("Uncaught exception: {}", exceptionStr));
|
crashCallback(hex::format("Uncaught exception: {}", exceptionStr));
|
||||||
|
|
||||||
// reset signal handlers prior to calling the original handler, because it may raise a signal
|
// Reset signal handlers prior to calling the original handler, because it may raise a signal
|
||||||
for(auto signal : Signals) std::signal(signal, SIG_DFL);
|
for(auto signal : Signals) std::signal(signal, SIG_DFL);
|
||||||
|
|
||||||
// call the original handler of C++ std
|
// Restore the original handler of C++ std
|
||||||
originalHandler();
|
std::set_terminate(originalHandler);
|
||||||
|
|
||||||
log::error("Should not happen: original std::set_terminate handler returned. Terminating manually");
|
#if defined(DEBUG)
|
||||||
exit(EXIT_FAILURE);
|
assert(!"Debug build, triggering breakpoint");
|
||||||
|
#else
|
||||||
|
std::terminate();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
log::error("Should not happen: catch block should be executed and terminate the program. Terminating manually");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save a backup project when the application crashes
|
// Save a backup project when the application crashes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user