Slight tweaks for CreatureException, add tests to see if what() works.
This commit is contained in:
parent
c3b573c7da
commit
07700008f7
|
@ -8,9 +8,10 @@ class CreatureException : std::exception {
|
||||||
std::string _error;
|
std::string _error;
|
||||||
|
|
||||||
public:
|
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
|
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifdef TESTS_BUILD
|
||||||
|
#include <cstring>
|
||||||
|
#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
|
Loading…
Reference in New Issue