10#include "../macros.hpp"
12#include "debugger.hpp"
25hi_export_module(hikogui.utility.terminate);
27hi_export
namespace hi {
35inline void call_atterminate() noexcept
37 auto const lock = std::scoped_lock(terminate_mutex);
38 for (
auto it = atterminate_functions.rbegin(); it != atterminate_functions.rend(); ++it) {
50 auto const lock = std::scoped_lock(detail::terminate_mutex);
51 detail::atterminate_functions.push_back(
std::move(f));
68 using namespace std::literals;
70 detail::call_atterminate();
81 title =
"Unhandled std::exception."s;
85 title =
"Unhandled unknown exception."s;
86 message +=
"<no data>"s;
90 title =
"Abnormal termination."s;
91 if (
auto message_cstr = get_debug_message()) {
92 message += message_cstr;
94 message +=
"<unknown>";
99 message +=
"\n\nStack Trace:\n";
101 auto stack_trace = std::stacktrace::current(0, 25);
104 for (
auto entry : stack_trace) {
105 if (entry and not(entry.source_file().empty() and entry.source_line() == 0 and entry.description().empty())) {
106 message += std::format(
"{}. {}:{} {}\n", depth, entry.source_file(), entry.source_line(), entry.description());
108 message += std::format(
"{}. <information is unavailable>\n", depth);
113 if (not
dialog(title, message)) {
115 std::println(stderr,
"{}\n{}", title, message);
The HikoGUI namespace.
Definition array_generic.hpp:20
std::terminate_handler old_terminate_handler
The old terminate handler.
Definition terminate.hpp:58
void atterminate(std::function< void()> f) noexcept
Register functions that need to be called on std::terminate().
Definition terminate.hpp:48
std::expected< dialog_button, std::error_code > dialog(std::string_view title, std::string_view text, dialog_button_mask button_mask=dialog_button_mask::ok) noexcept
Display a modal dialog.
Definition dialog_win32_impl.hpp:20
void terminate_handler() noexcept
The HikoGUI terminate handler.
Definition terminate.hpp:66
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T current_exception(T... args)
T rethrow_exception(T... args)