HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
exception_intf.hpp
1// Copyright Take Vos 2020-2021.
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 "../macros.hpp"
11#include "misc.hpp"
12#include <exception>
13#include <stdexcept>
14#include <bit>
15#include <format>
16#include <atomic>
17
18hi_export_module(hikogui.utility.exception : intf);
19
20hi_export namespace hi { inline namespace v1 {
21
27hi_export [[nodiscard]] std::string get_last_error_message(uint32_t error_code);
28
33hi_export [[nodiscard]] std::string get_last_error_message();
34
48hi_export class parse_error : public std::runtime_error {
49public:
51
60 template<typename It, typename... Args>
61 [[nodiscard]] constexpr parse_error(It first, It last, int tab_size, char const *msg, Args const&...args) noexcept :
62 runtime_error(make_what(first, last, tab_size, msg, args...))
63 {
64 }
65
73 template<typename It, typename... Args>
74 [[nodiscard]] constexpr parse_error(It first, It last, char const *msg, Args const&...args) noexcept :
75 parse_error(first, last, 8, msg, args...)
76 {
77 }
78
86 template<typename It>
87 [[nodiscard]] constexpr static std::pair<size_t, size_t> get_line_position(It first, It last, size_t tab_size) noexcept
88 {
89 auto line_nr = 0_uz;
90 auto column_nr = 0_uz;
91
92 auto c32 = char32_t{};
93 auto continue_count = int{};
94 while (first != last) {
95 auto const c8 = char_cast<char8_t>(*first++);
96
97 if ((c8 & 0xc0) == 0x80) {
98 --continue_count;
99 c32 <<= 6;
100 c32 |= c8 & 0x3f;
101
102 } else if (c8 & 0x80) {
103 continue_count = std::countl_one(c8) - 1;
104 c32 = c8 & (0b00'111'111 >> continue_count);
105
106 } else {
107 continue_count = 0;
108 c32 = c8;
109 }
110
111 if (not continue_count) {
112 ++column_nr;
113 switch (c32) {
114 case '\n':
115 case '\v':
116 case '\f':
117 case U'\u0085':
118 case U'\u2028':
119 case U'\u2029':
120 ++line_nr;
121 [[fallthrough]];
122 case '\r':
123 column_nr = 0;
124 break;
125 case '\t':
126 column_nr /= tab_size;
127 column_nr *= tab_size;
128 break;
129 default:;
130 }
131 }
132 }
133
134 return {line_nr, column_nr};
135 }
136
137private:
138 template<typename It, typename... Args>
139 [[nodiscard]] constexpr static std::string
140 make_what(It first, It last, size_t tab_size, char const *msg, Args const&...args) noexcept
141 {
142 auto const[line_nr, column_nr] = get_line_position(first, last, tab_size);
143 return {std::format("{}:{}: {}", line_nr + 1, column_nr + 1, std::format(msg, args...))};
144 }
145};
146
149hi_export class not_found_error : public std::runtime_error {
150public:
152};
153
161hi_export class operation_error : public std::runtime_error {
162public:
164};
165
173hi_export class io_error : public std::runtime_error {
174public:
176};
177
184hi_export class os_error : public std::runtime_error {
185public:
187};
188
189hi_export class gfx_error : public std::runtime_error {
190public:
192};
193
194hi_export class gui_error : public std::runtime_error {
195public:
197};
198
199hi_export class key_error : public std::runtime_error {
200public:
202};
203
204hi_export class url_error : public std::runtime_error {
205public:
207};
208
209hi_export class uri_error : public parse_error {
210public:
212};
213
218hi_export class cancel_error : public std::runtime_error {
219public:
221};
222
223}} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
hi_export std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:30
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Exception thrown during parsing on an error.
Definition exception_intf.hpp:48
constexpr parse_error(It first, It last, char const *msg, Args const &...args) noexcept
Create a parse error at a specific point in UTF-8 encoded text.
Definition exception_intf.hpp:74
static constexpr std::pair< size_t, size_t > get_line_position(It first, It last, size_t tab_size) noexcept
Get the line and column position of an iterator in a UTF-8 string.
Definition exception_intf.hpp:87
constexpr parse_error(It first, It last, int tab_size, char const *msg, Args const &...args) noexcept
Create a parse error at a specific point in UTF-8 encoded text.
Definition exception_intf.hpp:61
Exception thrown when an item was not found.
Definition exception_intf.hpp:149
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:161
Exception thrown during I/O on an error.
Definition exception_intf.hpp:173
Exception thrown during an operating system call.
Definition exception_intf.hpp:184
Definition exception_intf.hpp:189
Definition exception_intf.hpp:194
Definition exception_intf.hpp:199
Definition exception_intf.hpp:204
Definition exception_intf.hpp:209
Cancel error is caused by user pressing cancel.
Definition exception_intf.hpp:218