ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Errors.hpp
Go to the documentation of this file.
1 
9 #ifndef RAD_ERRORS_HPP
10 #define RAD_ERRORS_HPP
11 
12 #include <system_error> // bring in std::error_code et al
13 
14 namespace rad {
15 
16 enum class ErrorCodes {
17  CANCELLED = 0, // Operation cancelled
20  UNKNOWN
21 };
22 
23 class ErrorCategory : public std::error_category {
24  public:
25  const char* name() const noexcept override final {
26  return "RAD Error";
27  }
28 
29  std::string message(int errValue) const override final {
30  switch (static_cast<rad::ErrorCodes>(errValue)) {
32  return "Reply timed out.";
34  return "Operation was cancelled.";
36  return "Error parsing message payload.";
38  default:
39  return "Unknown error";
40  }
41  }
42 };
43 
44 extern inline const ErrorCategory& GetErrorCategory() {
45  static rad::ErrorCategory cat;
46  return cat;
47 }
48 
49 // Overload the global make_error_code() free function with our custom enum.
51  return {static_cast<int>(e), rad::GetErrorCategory()};
52 }
53 
54 } // namespace rad
55 
56 namespace std {
57 
58 // Register rad::ErrorCodes in the standard C++11 error code system
59 template <>
60 struct is_error_code_enum<rad::ErrorCodes> : std::true_type {};
61 
62 } // namespace std
63 
64 #endif /* RAD_ERRORS_HPP */
Definition: Errors.hpp:23
const ErrorCategory & GetErrorCategory()
Definition: Errors.hpp:44
std::string message(int errValue) const overridefinal
Definition: Errors.hpp:29
const char * name() const noexceptoverridefinal
Definition: Errors.hpp:25
ErrorCodes
Definition: Errors.hpp:16
std::error_code make_error_code(rad::ErrorCodes e)
Definition: Errors.hpp:50
optional int32 error_code
Definition: topics.proto:14
std::string const
Definition: Test{{cookiecutter.device_name}}.cpp:209