diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp index 2f932fb3e8ab9..7c2fe5f1cf4bb 100644 --- a/main/gui/source/main.cpp +++ b/main/gui/source/main.cpp @@ -23,32 +23,40 @@ namespace hex::init { * @return Exit code */ int main(int argc, char **argv) { - using namespace hex; - - // Set the main thread's name to "Main" - TaskManager::setCurrentThreadName("Main"); - - // Setup crash handlers right away to catch crashes as early as possible - crash::setupCrashHandlers(); - - // Run platform-specific initialization code - Window::initNative(); - - // Handle command line arguments if any have been passed - if (argc > 1) { - init::runCommandLine(argc, argv); + try { + using namespace hex; + + // Set the main thread's name to "Main" + TaskManager::setCurrentThreadName("Main"); + + // Setup crash handlers right away to catch crashes as early as possible + crash::setupCrashHandlers(); + + // Run platform-specific initialization code + Window::initNative(); + + // Handle command line arguments if any have been passed + if (argc > 1) { + init::runCommandLine(argc, argv); + } + + // Log some system information to aid debugging when users share their logs + log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); + log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); + log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture()); + + #if defined(OS_LINUX) + if (auto distro = ImHexApi::System::getLinuxDistro(); distro.has_value()) { + log::info("Linux distribution: {}. Version: {}", distro->name, distro->version.empty() ? "None" : distro->version); + } else { + log::warning("Linux distribution information is not available."); + } + #endif + + // Run ImHex + return init::runImHex(); + } catch (const std::exception &e) { + std::cerr << "Unhandled exception: " << e.what() << std::endl; + return EXIT_FAILURE; } - - // Log some system information to aid debugging when users share their logs - log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); - log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); - log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture()); - #if defined(OS_LINUX) - auto distro = ImHexApi::System::getLinuxDistro().value(); - log::info("Linux distribution: {}. Version: {}", distro.name, distro.version == "" ? "None" : distro.version); - #endif - - - // Run ImHex - return init::runImHex(); }