hueplusplus  1.0.0
HueException.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_HUE_EXCEPTION_H
24 #define INCLUDE_HUEPLUSPLUS_HUE_EXCEPTION_H
25 
26 #include <exception>
27 #include <string>
28 
29 #include "json/json.hpp"
30 
31 namespace hueplusplus
32 {
34 struct FileInfo
35 {
37  std::string filename;
39  int line = -1;
41  std::string func;
42 
45  std::string ToString() const;
46 };
47 
49 class HueException : public std::exception
50 {
51 public:
56  HueException(FileInfo fileInfo, const std::string& message);
57 
60  const char* what() const noexcept override;
61 
63  const FileInfo& GetFile() const noexcept;
64 
65 protected:
73  HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message);
74 
75 private:
76  std::string whatMessage;
77  FileInfo fileInfo;
78 };
79 
84 {
85 public:
92  HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description);
93 
97  int GetErrorNumber() const noexcept;
99  const std::string& GetAddress() const noexcept;
101  const std::string& GetDescription() const noexcept;
102 
108  static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json& response);
109 
110 private:
112  static std::string GetMessage(int error, const std::string& addr, const std::string& description);
113 
114 private:
115  int error;
116  std::string address;
117  std::string description;
118 };
119 } // namespace hueplusplus
120 
121 #endif
Exception class with file information. Base class of all custom exception classes.
Definition: HueException.h:49
std::string func
Current function from func. Empty if unknown.
Definition: HueException.h:41
std::string ToString() const
String representation of func, file and line.
Definition: HueException.cpp:104
Namespace for the hueplusplus library.
Definition: Action.h:27
std::string filename
Current file name from FILE. Empty if unknown.
Definition: HueException.h:37
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
int line
Current line number from LINE. -1 if unknown.
Definition: HueException.h:39
Exception caused by a Hue API "error" response with additional information.
Definition: HueException.h:83