namespace bastion noreturn inline static void throwSystemError std str

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace bastion {
[[noreturn]] inline static void throwSystemError(std::string const &message) {
throw std::system_error(errno, std::generic_category(), message);
}
[[noreturn]] inline static void throwSystemError(std::string const &message, std::error_code code) {
throw std::system_error(code.value(), code.category(), message);
}
template<typename ...Args>
[[noreturn]] inline static void throwSystemError(std::string const &format, Args &&...args) {
throwSystemError(fmt::sprintf(format, std::forward<Args>(args)...));
}
template<typename T>
inline static T checkCall(T result, char const *call, char const *function, char const *file, int line) {
static_assert(std::is_integral_v<T>);
if (result < 0)
throwSystemError("Error in function %s at %s (file %s, line %d)", function, call, file, line);
return result;
}
}
#define CHECKED(call) bastion::checkCall(call, #call, __PRETTY_FUNCTION__, __FILE__, __LINE__)