Tweaks for exception handling.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
e2e706693b
commit
13c4609cdd
|
@ -1,3 +1,4 @@
|
||||||
#include "Core.hpp"
|
#include "Core.hpp"
|
||||||
|
|
||||||
|
std::string ExceptionHandler::_creatureLibLastException = "";
|
||||||
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
||||||
|
|
|
@ -11,15 +11,15 @@
|
||||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||||
|
|
||||||
class ExceptionHandler {
|
class ExceptionHandler {
|
||||||
static std::string _lastException;
|
static std::string _creatureLibLastException;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void SetLastException(std::string function, const std::exception& e) {
|
static void SetLastException(std::string function, const std::exception& e) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "[" << function << "] " << e.what();
|
ss << "[" << function << "] " << e.what();
|
||||||
_lastException = ss.str();
|
_creatureLibLastException = ss.str();
|
||||||
}
|
}
|
||||||
static const char* GetLastException() { return _lastException.c_str(); }
|
static const char* GetLastException() { return _creatureLibLastException.c_str(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define Try(data) \
|
#define Try(data) \
|
||||||
|
|
|
@ -19,7 +19,7 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
||||||
AssertNotNull(choice)
|
AssertNotNull(choice);
|
||||||
if (!CanUse(choice))
|
if (!CanUse(choice))
|
||||||
return false;
|
return false;
|
||||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "CreateCreature.hpp"
|
#include "CreateCreature.hpp"
|
||||||
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../Library/BattleLibrary.hpp"
|
#include "../Library/BattleLibrary.hpp"
|
||||||
|
|
||||||
|
@ -21,8 +22,9 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
|
CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) {
|
||||||
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves())
|
if (_attacks.Count() >= _library->GetSettings()->GetMaximalMoves()) {
|
||||||
THROW_CREATURE("You have already set the maximum amount of allowed moves.");
|
THROW_CREATURE("You have already set the maximum amount of allowed moves.");
|
||||||
|
}
|
||||||
|
|
||||||
auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash());
|
auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash());
|
||||||
_attacks.Append(std::tuple(attackData, learnMethod));
|
_attacks.Append(std::tuple(attackData, learnMethod));
|
||||||
|
|
|
@ -13,9 +13,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
#define THROW_CREATURE(message) \
|
#define THROW_CREATURE(message) \
|
||||||
{ \
|
std::stringstream ___ss; \
|
||||||
std::stringstream ss; \
|
___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
|
||||||
ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
|
throw CreatureException(___ss.str());
|
||||||
throw CreatureException(ss.str()); \
|
|
||||||
}
|
|
||||||
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
||||||
|
|
Loading…
Reference in New Issue