Make CreatureException inherit from runtime_error.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
442d6cd5b1
commit
be6b2778a5
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue