exception logger
This commit is contained in:
+19
@@ -1,6 +1,7 @@
|
|||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <exception>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
|
||||||
@@ -151,6 +152,24 @@ namespace anm2ed
|
|||||||
info("Exiting Anm2Ed");
|
info("Exiting Anm2Ed");
|
||||||
stderr_redirect_stop();
|
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;
|
anm2ed::Logger logger;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -70,6 +71,8 @@ namespace anm2ed
|
|||||||
~Logger();
|
~Logger();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int log_exceptions(const std::function<int()>&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern anm2ed::Logger logger;
|
extern anm2ed::Logger logger;
|
||||||
|
|||||||
+10
-6
@@ -1,4 +1,5 @@
|
|||||||
#include "loader.hpp"
|
#include "loader.hpp"
|
||||||
|
#include "log.hpp"
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -10,16 +11,19 @@
|
|||||||
|
|
||||||
int main(int argc, const char** argv)
|
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)
|
while (!state.isQuit)
|
||||||
state.loop(loader.window, loader.settings);
|
state.loop(loader.window, loader.settings);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|||||||
Reference in New Issue
Block a user