HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
terminate.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
8#pragma once
9
10#include "../utility/utility.hpp"
11#include "../console/console.hpp"
12#include "../telemetry/telemetry.hpp"
13#include "../macros.hpp"
14#include <exception>
15#include <stdexcept>
16#include <atomic>
17#include <bit>
18#include <format>
19
20hi_export_module(hikogui.crt.terminate);
21
22namespace hi { inline namespace v1 {
23
29
37 using namespace std::literals;
38
39 log_global.flush();
40
41 auto title = std::string_view{};
42 auto message = std::string_view{};
43
44 hilet ep = std::current_exception();
45 if (ep) {
46 try {
48
49 } catch (std::exception const& e) {
50 title = "Unhandled std::exception."sv;
51 message = e.what();
52
53 } catch (...) {
54 title = "Unhandled unknown exception."sv;
55 message = "<no data>"sv;
56 }
57
58 std::cerr << std::format("{}\n{}\n", title, message);
59
60 } else {
61 title = "Abnormal termination."sv;
62 message = debug_message.exchange(nullptr, std::memory_order::relaxed);
63 }
64
65 dialog_ok(title, message);
66
68}
69
70}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::terminate_handler old_terminate_handler
The old terminate handler.
Definition terminate.hpp:28
std::atomic< char const * > debug_message
Message to show when the application is terminated because of a debug_abort.
Definition debugger_intf.hpp:20
void terminate_handler() noexcept
The HikoGUI terminate handler.
Definition terminate.hpp:36
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
hi_no_inline void flush() noexcept
Flush all messages from the log_queue directly from this thread.
Definition log.hpp:145
T current_exception(T... args)
T rethrow_exception(T... args)
T what(T... args)