diff --git a/src/Core/Exceptions/CreatureException.hpp b/src/Core/Exceptions/CreatureException.hpp index d316d33..a66dc51 100644 --- a/src/Core/Exceptions/CreatureException.hpp +++ b/src/Core/Exceptions/CreatureException.hpp @@ -8,9 +8,10 @@ class CreatureException : std::exception { std::string _error; public: - CreatureException(std::string error) : _error(error) {} + explicit CreatureException(std::string error) : _error(error) {} + const char* what() const throw() override { return _error.c_str(); } - const char* what() const noexcept override { return _error.c_str(); } + virtual ~CreatureException() = default; }; #endif // CREATURELIB_CREATUREEXCEPTION_HPP diff --git a/tests/ExceptionTests.cpp b/tests/ExceptionTests.cpp new file mode 100644 index 0000000..1c34155 --- /dev/null +++ b/tests/ExceptionTests.cpp @@ -0,0 +1,15 @@ +#ifdef TESTS_BUILD +#include +#include "../extern/catch.hpp" +#include "../src/Core/Exceptions/CreatureException.hpp" + +TEST_CASE("When throwing exception, what() is readable", "[Utilities]") { + try { + throw CreatureException("foobar"); + } catch (const CreatureException& e) { + INFO(e.what()); + REQUIRE(strcmp(e.what(), "foobar") == 0); + } +} + +#endif \ No newline at end of file