hueplusplus 1.2.0
Loading...
Searching...
No Matches
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 <nlohmann/json.hpp>
30
31namespace hueplusplus
32{
35{
37 std::string filename;
39 int line = -1;
41 std::string func;
42
45 std::string ToString() const;
46};
47
49class HueException : public std::exception
50{
51public:
56 HueException(FileInfo fileInfo, const std::string& message);
57
60 const char* what() const noexcept override;
61
63 const FileInfo& GetFile() const noexcept;
64
65protected:
73 HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message);
74
75private:
76 std::string whatMessage;
77 FileInfo fileInfo;
78};
79
84{
85public:
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
110private:
112 static std::string GetMessage(int error, const std::string& addr, const std::string& description);
113
114private:
115 int error;
116 std::string address;
117 std::string description;
118};
119} // namespace hueplusplus
120
121#endif
Exception caused by a Hue API "error" response with additional information.
Definition HueException.h:84
const std::string & GetAddress() const noexcept
Address the API call tried to access.
Definition HueException.cpp:64
const std::string & GetDescription() const noexcept
Error description.
Definition HueException.cpp:69
static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json &response)
Creates exception from API response.
Definition HueException.cpp:74
int GetErrorNumber() const noexcept
Error number from Hue API error response.
Definition HueException.cpp:59
Exception class with file information. Base class of all custom exception classes.
Definition HueException.h:50
const FileInfo & GetFile() const noexcept
Filename and line where the exception was thrown or caused by.
Definition HueException.cpp:36
const char * what() const noexcept override
What message of the exception.
Definition HueException.cpp:31
Namespace for the hueplusplus library.
Definition Action.h:28
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35
std::string filename
Current file name from FILE. Empty if unknown.
Definition HueException.h:37
int line
Current line number from LINE. -1 if unknown.
Definition HueException.h:39
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