rad  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
15 namespace rad {
16 
17 enum class ErrorCodes {
18  CANCELLED = 0, // Operation cancelled
21  UNKNOWN
22 };
23 
24 class 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 
43 extern inline const ErrorCategory& GetErrorCategory() {
44  static rad::ErrorCategory cat;
45  return cat;
46 }
47 
51 // NOLINTNEXTLINE
52 inline std::error_code make_error_code(rad::ErrorCodes e) {
53  return {static_cast<int>(e), rad::GetErrorCategory()};
54 }
55 
56 } // namespace rad
57 
58 namespace std {
59 
60 // Register rad::ErrorCodes in the standard C++11 error code system
61 template <>
62 struct is_error_code_enum<rad::ErrorCodes> : std::true_type {};
63 
64 } // namespace std
65 
66 #endif // RAD_ERRORS_HPP
Definition: errors.hpp:24
const ErrorCategory & GetErrorCategory()
Definition: errors.hpp:43
const char * name() const noexceptoverridefinal
Definition: errors.hpp:26
ErrorCodes
Definition: errors.hpp:17
std::string message(int err_value) const overridefinal
Definition: errors.hpp:28
std::error_code make_error_code(rad::ErrorCodes e)
Definition: errors.hpp:52