Make CreatureException inherit from runtime_error.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-02-22 15:07:16 +01:00
parent 442d6cd5b1
commit be6b2778a5
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 7 additions and 8 deletions

View File

@ -1,16 +1,12 @@
#ifndef CREATURELIB_CREATUREEXCEPTION_HPP #ifndef CREATURELIB_CREATUREEXCEPTION_HPP
#define CREATURELIB_CREATUREEXCEPTION_HPP #define CREATURELIB_CREATUREEXCEPTION_HPP
#include <exception> #include <stdexcept>
#include <string> #include <string>
class CreatureException : std::exception { class CreatureException : public std::runtime_error {
std::string _error;
public: public:
explicit CreatureException(std::string error) : _error(error) {} explicit CreatureException(const std::string& error) : std::runtime_error(error) {}
const char* what() const throw() override { return _error.c_str(); }
virtual ~CreatureException() = default; virtual ~CreatureException() = default;
}; };

View File

@ -4,12 +4,15 @@
#include "../src/Core/Exceptions/CreatureException.hpp" #include "../src/Core/Exceptions/CreatureException.hpp"
TEST_CASE("When throwing exception, what() is readable", "[Utilities]") { TEST_CASE("When throwing exception, what() is readable", "[Utilities]") {
bool hasCaught = false;
try { try {
throw CreatureException("foobar"); throw CreatureException("foobar");
} catch (const CreatureException& e) { } catch (const std::exception& e) {
hasCaught = true;
INFO(e.what()); INFO(e.what());
REQUIRE(strcmp(e.what(), "foobar") == 0); REQUIRE(strcmp(e.what(), "foobar") == 0);
} }
REQUIRE(hasCaught);
} }
#endif #endif