Commit ce79be3602f6f830e5a3a4b35aa7312ffbb363d9
Committed by
Jan
1 parent
9c709358
Add documentatio to exceptions.
Showing
5 changed files
with
93 additions
and
51 deletions
hueplusplus/BaseHttpHandler.cpp
| ... | ... | @@ -4,17 +4,20 @@ |
| 4 | 4 | Copyright (C) 2020 Jan Rogall - developer\n |
| 5 | 5 | Copyright (C) 2020 Moritz Wirger - developer\n |
| 6 | 6 | |
| 7 | - This program is free software; you can redistribute it and/or modify | |
| 8 | - it under the terms of the GNU General Public License as published by | |
| 9 | - the Free Software Foundation; either version 3 of the License, or | |
| 7 | + This file is part of hueplusplus. | |
| 8 | + | |
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | |
| 10 | + it under the terms of the GNU Lesser General Public License as published by | |
| 11 | + the Free Software Foundation, either version 3 of the License, or | |
| 10 | 12 | (at your option) any later version. |
| 11 | - This program is distributed in the hope that it will be useful, | |
| 13 | + | |
| 14 | + hueplusplus is distributed in the hope that it will be useful, | |
| 12 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - GNU General Public License for more details. | |
| 15 | - You should have received a copy of the GNU General Public License | |
| 16 | - along with this program; if not, write to the Free Software Foundation, | |
| 17 | - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + GNU Lesser General Public License for more details. | |
| 18 | + | |
| 19 | + You should have received a copy of the GNU Lesser General Public License | |
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | 21 | **/ |
| 19 | 22 | |
| 20 | 23 | #include "include/BaseHttpHandler.h" | ... | ... |
hueplusplus/HueException.cpp
| ... | ... | @@ -4,23 +4,26 @@ |
| 4 | 4 | Copyright (C) 2020 Jan Rogall - developer\n |
| 5 | 5 | Copyright (C) 2020 Moritz Wirger - developer\n |
| 6 | 6 | |
| 7 | - This program is free software; you can redistribute it and/or modify | |
| 8 | - it under the terms of the GNU General Public License as published by | |
| 9 | - the Free Software Foundation; either version 3 of the License, or | |
| 7 | + This file is part of hueplusplus. | |
| 8 | + | |
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | |
| 10 | + it under the terms of the GNU Lesser General Public License as published by | |
| 11 | + the Free Software Foundation, either version 3 of the License, or | |
| 10 | 12 | (at your option) any later version. |
| 11 | - This program is distributed in the hope that it will be useful, | |
| 13 | + | |
| 14 | + hueplusplus is distributed in the hope that it will be useful, | |
| 12 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - GNU General Public License for more details. | |
| 15 | - You should have received a copy of the GNU General Public License | |
| 16 | - along with this program; if not, write to the Free Software Foundation, | |
| 17 | - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + GNU Lesser General Public License for more details. | |
| 18 | + | |
| 19 | + You should have received a copy of the GNU Lesser General Public License | |
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | 21 | **/ |
| 19 | 22 | |
| 20 | 23 | #include "include/HueException.h" |
| 21 | 24 | |
| 22 | 25 | HueException::HueException(FileInfo fileInfo, const std::string& message) |
| 23 | - : HueException("Hue exception", std::move(fileInfo), message) | |
| 26 | + : HueException("HueException", std::move(fileInfo), message) | |
| 24 | 27 | {} |
| 25 | 28 | |
| 26 | 29 | const char* HueException::what() const noexcept |
| ... | ... | @@ -37,7 +40,7 @@ HueException::HueException(const char* exceptionName, FileInfo fileInfo, const s |
| 37 | 40 | : fileInfo(std::move(fileInfo)) |
| 38 | 41 | { |
| 39 | 42 | whatMessage = exceptionName; |
| 40 | - whatMessage.append(" from"); | |
| 43 | + whatMessage.append(" from "); | |
| 41 | 44 | whatMessage.append(this->fileInfo.ToString()); |
| 42 | 45 | whatMessage.append(" "); |
| 43 | 46 | whatMessage.append(message); |
| ... | ... | @@ -45,7 +48,7 @@ HueException::HueException(const char* exceptionName, FileInfo fileInfo, const s |
| 45 | 48 | |
| 46 | 49 | HueAPIResponseException::HueAPIResponseException( |
| 47 | 50 | FileInfo fileInfo, int error, std::string address, std::string description) |
| 48 | - : HueException("Hue api response exception", std::move(fileInfo), GetMessage(error, address, description)), | |
| 51 | + : HueException("HueApiResponseException", std::move(fileInfo), GetMessage(error, address, description)), | |
| 49 | 52 | error(error), |
| 50 | 53 | address(std::move(address)), |
| 51 | 54 | description(std::move(description)) | ... | ... |
hueplusplus/include/HueException.h
| ... | ... | @@ -4,17 +4,20 @@ |
| 4 | 4 | Copyright (C) 2020 Jan Rogall - developer\n |
| 5 | 5 | Copyright (C) 2020 Moritz Wirger - developer\n |
| 6 | 6 | |
| 7 | - This program is free software; you can redistribute it and/or modify | |
| 8 | - it under the terms of the GNU General Public License as published by | |
| 9 | - the Free Software Foundation; either version 3 of the License, or | |
| 7 | + This file is part of hueplusplus. | |
| 8 | + | |
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | |
| 10 | + it under the terms of the GNU Lesser General Public License as published by | |
| 11 | + the Free Software Foundation, either version 3 of the License, or | |
| 10 | 12 | (at your option) any later version. |
| 11 | - This program is distributed in the hope that it will be useful, | |
| 13 | + | |
| 14 | + hueplusplus is distributed in the hope that it will be useful, | |
| 12 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - GNU General Public License for more details. | |
| 15 | - You should have received a copy of the GNU General Public License | |
| 16 | - along with this program; if not, write to the Free Software Foundation, | |
| 17 | - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + GNU Lesser General Public License for more details. | |
| 18 | + | |
| 19 | + You should have received a copy of the GNU Lesser General Public License | |
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | 21 | **/ |
| 19 | 22 | |
| 20 | 23 | #ifndef _HUE_EXCEPTION_H |
| ... | ... | @@ -26,19 +29,30 @@ |
| 26 | 29 | //! \brief Contains information about error location, use CURRENT_FILE_INFO to create |
| 27 | 30 | struct FileInfo |
| 28 | 31 | { |
| 32 | + //! \brief Current file name from __FILE__. Empty if unknown | |
| 29 | 33 | std::string filename; |
| 34 | + //! \brief Current line number from __LINE__. -1 if unknown | |
| 30 | 35 | int line = -1; |
| 36 | + //! \brief Current function from __func__. Empty if unknown | |
| 31 | 37 | std::string func; |
| 32 | 38 | |
| 39 | + //! \brief String representation of func, file and line. | |
| 40 | + //! \returns "<func> in <filename>:<line>" or "Unknown file" if unknown. | |
| 33 | 41 | std::string ToString() const; |
| 34 | 42 | }; |
| 35 | 43 | |
| 44 | +//! \brief Exception class with file information. Base class of all custom exception classes | |
| 36 | 45 | class HueException : public std::exception |
| 37 | 46 | { |
| 38 | 47 | public: |
| 39 | - //! \brief Creates HueException with information about the thrown location | |
| 48 | + //! \brief Creates HueException with information about the error and source | |
| 49 | + //! \param fileInfo Source of the error. Must not always be the throw location, | |
| 50 | + //! can also be a calling function which matches the cause better. | |
| 51 | + //! \param message Human readable error message. | |
| 40 | 52 | HueException(FileInfo fileInfo, const std::string& message); |
| 41 | 53 | |
| 54 | + //! \brief What message of the exception | |
| 55 | + //! \returns exception name, file info and constructor message as char* into member string | |
| 42 | 56 | const char* what() const noexcept override; |
| 43 | 57 | |
| 44 | 58 | //! \brief Filename and line where the exception was thrown or caused by |
| ... | ... | @@ -48,6 +62,10 @@ protected: |
| 48 | 62 | //! \brief Creates HueException with child class name |
| 49 | 63 | //! |
| 50 | 64 | //! Should be used by subclasses which can append additional information to the end of whatMessage. |
| 65 | + //! \param exceptionName class name of the subclass | |
| 66 | + //! \param fileInfo Source of the error. Must not always be the throw location, | |
| 67 | + //! can also be a calling function which matches the cause better. | |
| 68 | + //! \param message Human readable error message | |
| 51 | 69 | HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message); |
| 52 | 70 | |
| 53 | 71 | private: |
| ... | ... | @@ -55,16 +73,31 @@ private: |
| 55 | 73 | FileInfo fileInfo; |
| 56 | 74 | }; |
| 57 | 75 | |
| 76 | +//! \brief Exception caused by a Hue API "error" response with additional information | |
| 77 | +//! | |
| 78 | +//! Refer to Hue developer documentation for more detail on specific error codes. | |
| 58 | 79 | class HueAPIResponseException : public HueException |
| 59 | 80 | { |
| 60 | 81 | public: |
| 82 | + //! \brief Create exception with info from Hue API error | |
| 83 | + //! \param fileInfo Source of the error. Must not always be the throw location, | |
| 84 | + //! can also be a calling function which matches the cause better. | |
| 85 | + //! \param error Hue API error code from error response. | |
| 86 | + //! \param address URI the API call referred to from error response. | |
| 87 | + //! \param description Error description from response. | |
| 61 | 88 | HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description); |
| 62 | 89 | |
| 90 | + //! \brief Error number from Hue API error response. | |
| 91 | + //! | |
| 92 | + //! Refer to Hue developer documentation for meaning of error codes. | |
| 63 | 93 | int GetErrorNumber() const noexcept; |
| 94 | + //! \brief Address the API call tried to access. | |
| 64 | 95 | const std::string& GetAddress() const noexcept; |
| 96 | + //! \brief Error description | |
| 65 | 97 | const std::string& GetDescription() const noexcept; |
| 66 | 98 | |
| 67 | 99 | private: |
| 100 | + //! \brief Creates exception message containing the given information | |
| 68 | 101 | static std::string GetMessage(int error, const std::string& addr, const std::string& description); |
| 69 | 102 | |
| 70 | 103 | private: | ... | ... |
hueplusplus/include/HueExceptionMacro.h
| ... | ... | @@ -4,20 +4,20 @@ |
| 4 | 4 | Copyright (C) 2020 Jan Rogall - developer\n |
| 5 | 5 | Copyright (C) 2020 Moritz Wirger - developer\n |
| 6 | 6 | |
| 7 | - This program is free software; you can redistribute it and/or modify | |
| 8 | - it under the terms of the GNU General Public License as published by | |
| 9 | - the Free Software Foundation; either version 3 of the License, or | |
| 7 | + This file is part of hueplusplus. | |
| 8 | + | |
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | |
| 10 | + it under the terms of the GNU Lesser General Public License as published by | |
| 11 | + the Free Software Foundation, either version 3 of the License, or | |
| 10 | 12 | (at your option) any later version. |
| 11 | - This program is distributed in the hope that it will be useful, | |
| 13 | + | |
| 14 | + hueplusplus is distributed in the hope that it will be useful, | |
| 12 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - GNU General Public License for more details. | |
| 15 | - You should have received a copy of the GNU General Public License | |
| 16 | - along with this program; if not, write to the Free Software Foundation, | |
| 17 | - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + GNU Lesser General Public License for more details. | |
| 18 | 18 | |
| 19 | - This file contains a macro definition for getting the current line number. | |
| 20 | - It should only be included in cpp files and not in headers! | |
| 19 | + You should have received a copy of the GNU Lesser General Public License | |
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | #include "HueException.h" | ... | ... |
hueplusplus/include/Utils.h
| ... | ... | @@ -4,17 +4,20 @@ |
| 4 | 4 | Copyright (C) 2020 Jan Rogall - developer\n |
| 5 | 5 | Copyright (C) 2020 Moritz Wirger - developer\n |
| 6 | 6 | |
| 7 | - This program is free software; you can redistribute it and/or modify | |
| 8 | - it under the terms of the GNU General Public License as published by | |
| 9 | - the Free Software Foundation; either version 3 of the License, or | |
| 7 | + This file is part of hueplusplus. | |
| 8 | + | |
| 9 | + hueplusplus is free software: you can redistribute it and/or modify | |
| 10 | + it under the terms of the GNU Lesser General Public License as published by | |
| 11 | + the Free Software Foundation, either version 3 of the License, or | |
| 10 | 12 | (at your option) any later version. |
| 11 | - This program is distributed in the hope that it will be useful, | |
| 13 | + | |
| 14 | + hueplusplus is distributed in the hope that it will be useful, | |
| 12 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - GNU General Public License for more details. | |
| 15 | - You should have received a copy of the GNU General Public License | |
| 16 | - along with this program; if not, write to the Free Software Foundation, | |
| 17 | - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | + GNU Lesser General Public License for more details. | |
| 18 | + | |
| 19 | + You should have received a copy of the GNU Lesser General Public License | |
| 20 | + along with hueplusplus. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | 21 | **/ |
| 19 | 22 | |
| 20 | 23 | #ifndef _UTILS_H | ... | ... |