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"
|
||||
|
||||
std::string ExceptionHandler::_creatureLibLastException = "";
|
||||
export const char* CreatureLib_C_GetLastException() { return ExceptionHandler::GetLastException(); }
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
class ExceptionHandler {
|
||||
static std::string _lastException;
|
||||
static std::string _creatureLibLastException;
|
||||
|
||||
public:
|
||||
static void SetLastException(std::string function, const std::exception& e) {
|
||||
std::stringstream ss;
|
||||
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) \
|
||||
|
|
|
@ -19,7 +19,7 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
|||
}
|
||||
|
||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
AssertNotNull(choice);
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
choice->GetUser()->GetBattleSide()->SetChoice(choice);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "CreateCreature.hpp"
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include "../Library/BattleLibrary.hpp"
|
||||
|
||||
|
@ -21,8 +22,9 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) {
|
|||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash());
|
||||
_attacks.Append(std::tuple(attackData, learnMethod));
|
||||
|
|
|
@ -13,9 +13,8 @@ public:
|
|||
};
|
||||
|
||||
#define THROW_CREATURE(message) \
|
||||
{ \
|
||||
std::stringstream ss; \
|
||||
ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
|
||||
throw CreatureException(ss.str()); \
|
||||
}
|
||||
std::stringstream ___ss; \
|
||||
___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
|
||||
throw CreatureException(___ss.str());
|
||||
|
||||
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
||||
|
|
Loading…
Reference in New Issue