exception logger

This commit is contained in:
2026-05-11 17:55:00 -04:00
parent b345c27a87
commit e6a4065777
3 changed files with 32 additions and 6 deletions
+19
View File
@@ -1,6 +1,7 @@
#include "log.hpp"
#include <array>
#include <exception>
#include <format>
#include <print>
@@ -151,6 +152,24 @@ namespace anm2ed
info("Exiting Anm2Ed");
stderr_redirect_stop();
}
int log_exceptions(const std::function<int()>& callback)
{
try
{
return callback();
}
catch (const std::exception& e)
{
logger.fatal(std::format("Unhandled exception: {}", e.what()));
}
catch (...)
{
logger.fatal("Unhandled non-standard exception");
}
return EXIT_FAILURE;
}
}
anm2ed::Logger logger;
+3
View File
@@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
#include <functional>
#include <string>
#include <string_view>
#include <mutex>
@@ -70,6 +71,8 @@ namespace anm2ed
~Logger();
};
int log_exceptions(const std::function<int()>&);
}
extern anm2ed::Logger logger;
+10 -6
View File
@@ -1,4 +1,5 @@
#include "loader.hpp"
#include "log.hpp"
#include "state.hpp"
#ifdef _WIN32
@@ -10,16 +11,19 @@
int main(int argc, const char** argv)
{
anm2ed::Loader loader(argc, argv);
return anm2ed::log_exceptions([&]()
{
anm2ed::Loader loader(argc, argv);
if (loader.isError) return EXIT_FAILURE;
if (loader.isError) return EXIT_FAILURE;
anm2ed::State state(loader.window, loader.settings, loader.arguments);
anm2ed::State state(loader.window, loader.settings, loader.arguments);
while (!state.isQuit)
state.loop(loader.window, loader.settings);
while (!state.isQuit)
state.loop(loader.window, loader.settings);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
});
}
#ifdef _WIN32