exception logger
This commit is contained in:
+19
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "loader.hpp"
|
||||
#include "log.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -9,6 +10,8 @@
|
||||
#endif
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
return anm2ed::log_exceptions([&]()
|
||||
{
|
||||
anm2ed::Loader loader(argc, argv);
|
||||
|
||||
@@ -20,6 +23,7 @@ int main(int argc, const char** argv)
|
||||
state.loop(loader.window, loader.settings);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
Reference in New Issue
Block a user