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
#define CREATURELIB_CREATUREEXCEPTION_HPP
#include <exception>
#include <stdexcept>
#include <string>
class CreatureException : std::exception {
std::string _error;
class CreatureException : public std::runtime_error {
public:
explicit CreatureException(std::string error) : _error(error) {}
const char* what() const throw() override { return _error.c_str(); }
explicit CreatureException(const std::string& error) : std::runtime_error(error) {}
virtual ~CreatureException() = default;
};

View File

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