diff --git a/error/include/error/error.hpp b/error/include/error/error.hpp index 0391eab..bd70762 100644 --- a/error/include/error/error.hpp +++ b/error/include/error/error.hpp @@ -5,9 +5,19 @@ namespace error { /** - * @brief A struct that represents error information. + * @brief A class that represents error information. */ -struct Error : public std::exception { +class Error : public std::exception { + private: + const char* message; /**< The error message. */ + + public: + /** + * @brief Constructs a new error with the given message. + * @param message An error message. + */ + Error(const char* message); + /** * @brief Returns the explanatory string. * @return Pointer to a null-terminated string with explanatory information. diff --git a/error/src/error.cpp b/error/src/error.cpp index 9020e7a..0c2d874 100644 --- a/error/src/error.cpp +++ b/error/src/error.cpp @@ -2,6 +2,8 @@ namespace error { -const char* Error::what() const noexcept { return "unknown error"; } +Error::Error(const char* message) : message(message) {} + +const char* Error::what() const noexcept { return message; } } // namespace error diff --git a/error/test/error_test.cpp b/error/test/error_test.cpp index f96f4e8..b19334d 100644 --- a/error/test/error_test.cpp +++ b/error/test/error_test.cpp @@ -1,8 +1,9 @@ #include #include +#include -TEST_CASE("test Error::what") { - const error::Error err; +TEST_CASE("Constructs an error") { + const error::Error err("unknown error"); const std::string expected("unknown error"); REQUIRE(expected.compare(err.what()) == 0); }