19 #ifndef PSTORE_SUPPORT_ERROR_HPP 20 #define PSTORE_SUPPORT_ERROR_HPP 23 #include <system_error> 27 # define WIN32_LEAN_AND_MEAN 33 #ifndef PSTORE_EXCEPTIONS 39 #define PSTORE_ERROR_CODES \ 41 X (transaction_on_read_only_database) 43 X (unknown_revision) \ 45 X (header_version_mismatch) \ 49 X (index_not_latest_revision) \ 50 X (unknown_process_path) \ 52 X (cannot_allocate_after_commit) 55 X (read_only_address) \ 56 X (did_not_read_number_of_bytes_requested) \ 57 X (uuid_parse_error) \ 58 X (bad_message_part_number) \ 59 X (unable_to_open_named_pipe) \ 60 X (pipe_write_timeout) \ 69 enum class error_code : int { PSTORE_ERROR_CODES };
82 char const * name ()
const noexcept
override;
83 std::string message (
int error)
const override;
86 std::error_category
const & get_error_category ();
88 inline std::error_code make_error_code (error_code
const erc) {
89 static_assert (std::is_same<std::underlying_type<decltype (erc)>::type,
int>::value,
90 "base type of pstore::error_code must be int to permit safe static cast");
91 return {
static_cast<int> (erc), get_error_category ()};
101 constexpr
explicit errno_erc (
int const err) noexcept
103 constexpr
int get ()
const noexcept {
return err_; }
109 inline std::error_code make_error_code (
errno_erc const erc) noexcept {
110 return {erc.get (), std::generic_category ()};
116 constexpr
explicit win32_erc (DWORD err) noexcept
118 constexpr
int get ()
const noexcept {
return err_; }
124 inline std::error_code make_error_code (win32_erc
const e) noexcept {
125 return {e.get (), std::system_category ()};
134 struct is_error_code_enum<
pstore::error_code> : std::true_type {};
136 struct is_error_code_enum<pstore::errno_erc> : std::true_type {};
140 struct is_error_code_enum<pstore::win32_erc> : std::true_type {};
147 template <
typename Exception,
typename =
typename std::enable_if<
148 std::is_base_of<std::exception, Exception>::value>::type>
149 PSTORE_NO_RETURN
void raise_exception (Exception
const & exc) {
150 #ifdef PSTORE_EXCEPTIONS 154 std::wcerr << L
"Error: " << utf::win32::to16 (exc.what ()) << L
'\n';
156 std::cerr <<
"Error: " << exc.what () <<
'\n';
158 std::exit (EXIT_FAILURE);
159 #endif // PSTORE_EXCEPTIONS 162 template <
typename ErrorCode>
163 PSTORE_NO_RETURN
void raise_error_code (ErrorCode erc) {
164 raise_exception (std::system_error{erc});
166 template <
typename ErrorCode,
typename StrType>
167 PSTORE_NO_RETURN
void raise_error_code (ErrorCode erc, StrType
const & what) {
168 raise_exception (std::system_error{erc, what});
171 template <
typename ErrorType>
172 PSTORE_NO_RETURN
void raise (ErrorType erc) {
173 raise_error_code (make_error_code (erc));
175 template <
typename ErrorType,
typename StrType>
176 PSTORE_NO_RETURN
void raise (ErrorType erc, StrType
const & what) {
177 raise_error_code (make_error_code (erc), what);
182 #endif // PSTORE_SUPPORT_ERROR_HPP Definition: chunked_sequence.hpp:607
This class is a tiny wrapper that allows an errno value to be passed to std::make_error_code().
Definition: error.hpp:99
Definition: nonpod2.cpp:40
Functionality for processing UTF-8 strings.