rad 6.2.0
Loading...
Searching...
No Matches
errors.hpp
Go to the documentation of this file.
1
10#ifndef RAD_ERRORS_HPP
11#define RAD_ERRORS_HPP
12
13#include <system_error> // bring in std::error_code et al
14
15namespace rad {
16
17enum class ErrorCodes {
18 CANCELLED = 0, // Operation cancelled
22};
23
24class ErrorCategory : public std::error_category {
25 public:
26 const char* name() const noexcept override final { return "RAD Error"; }
27
28 std::string message(int err_value) const override final {
29 switch (static_cast<rad::ErrorCodes>(err_value)) {
31 return "Reply timed out.";
33 return "Operation was cancelled.";
35 return "Error parsing message payload.";
37 default:
38 return "Unknown error";
39 }
40 }
41};
42
43extern inline const ErrorCategory& GetErrorCategory() {
44 static rad::ErrorCategory cat;
45 return cat;
46}
47
51// NOLINTNEXTLINE
52inline std::error_code make_error_code(rad::ErrorCodes e) {
53 return {static_cast<int>(e), rad::GetErrorCategory()};
54}
55
56} // namespace rad
57
58namespace std {
59
60// Register rad::ErrorCodes in the standard C++11 error code system
61template <>
62struct is_error_code_enum<rad::ErrorCodes> : std::true_type {};
63
64} // namespace std
65
66#endif // RAD_ERRORS_HPP
Definition errors.hpp:24
const char * name() const noexcept override final
Definition errors.hpp:26
std::string message(int err_value) const override final
Definition errors.hpp:28
Definition actionsApp.cpp:23
ErrorCodes
Definition errors.hpp:17
const ErrorCategory & GetErrorCategory()
Definition errors.hpp:43
std::error_code make_error_code(rad::ErrorCodes e)
Definition errors.hpp:52
Definition errors.hpp:58