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
|
||||
#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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue