Lely core libraries  2.3.4
error.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_UTIL_ERROR_HPP_
24 #define LELY_UTIL_ERROR_HPP_
25 
26 #include <lely/util/errnum.h>
27 
28 #include <string>
29 #include <system_error>
30 
31 namespace lely {
32 namespace util {
33 
38 inline ::std::error_code
39 make_error_code(int errc = get_errc()) noexcept {
40  return {errc, ::std::generic_category()};
41 }
42 
47 [[noreturn]] inline void
48 throw_error_code(::std::errc e) {
49  throw ::std::system_error(::std::make_error_code(e));
50 }
51 
57 [[noreturn]] inline void
58 throw_error_code(const ::std::string& what_arg, ::std::errc e) {
59  throw ::std::system_error(::std::make_error_code(e), what_arg);
60 }
61 
63 [[noreturn]] inline void
64 throw_error_code(const char* what_arg, ::std::errc e) {
65  throw ::std::system_error(::std::make_error_code(e), what_arg);
66 }
67 
72 [[noreturn]] inline void
73 throw_errc(int errc = get_errc()) {
74  throw ::std::system_error(make_error_code(errc));
75 }
76 
83 [[noreturn]] inline void
84 throw_errc(const ::std::string& what_arg, int errc = get_errc()) {
85  throw ::std::system_error(make_error_code(errc), what_arg);
86 }
87 
89 [[noreturn]] inline void
90 throw_errc(const char* what_arg, int errc = get_errc()) {
91  throw ::std::system_error(make_error_code(errc), what_arg);
92 }
93 
98 [[noreturn]] inline void
101 }
102 
109 [[noreturn]] inline void
110 throw_errnum(const ::std::string& what_arg, int errnum) {
111  throw_errc(what_arg, errnum2c(errnum));
112 }
113 
115 [[noreturn]] inline void
116 throw_errnum(const char* what_arg, int errnum) {
117  throw_errc(what_arg, errnum2c(errnum));
118 }
119 
120 } // namespace util
121 } // namespace lely
122 
123 #endif // !LELY_UTIL_ERROR_HPP_
This header file is part of the utilities library; it contains the native and platform-independent er...
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
Definition: errnum.c:810
errnum
The platform-independent error numbers.
Definition: errnum.h:77
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
Definition: errnum.c:932
void throw_error_code(::std::errc e)
Throws an std::system_error exception corresponding to the specified error code.
Definition: error.hpp:48
void throw_errnum(int errnum)
Throws an std::system_error exception corresponding to the specified platform-independent error numbe...
Definition: error.hpp:99
void throw_errc(int errc=get_errc())
Throws an std::system_error exception corresponding to the specified or current (thread-specific) nat...
Definition: error.hpp:73