More clearer exception messages.

This commit is contained in:
Deukhoofd 2020-07-30 20:15:27 +02:00
parent 29013bb6ac
commit b3b9698831
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 16 additions and 9 deletions

View File

@ -14,14 +14,11 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
}
while (queue->HasNext()) {
auto item = queue->Dequeue();
try {
ExecuteChoice(item.get());
} catch (const std::exception& e) {
THROW_CREATURE("Executing choice failed for choice by mon on side "
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetSideIndex()) << " and index "
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser()))
<< " with message '" << e.what() << "'.");
}
try_creature(ExecuteChoice(item.get()),
"Executing choice failed for choice by mon on side "
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetSideIndex()) << " and index "
<< ((uint32_t)item.get()->GetUser()->GetBattleSide()->GetCreatureIndex(item->GetUser()))
<< " with message");
}
queue->HasCompletedQueue = true;
}
@ -53,7 +50,9 @@ void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
switch (choiceKind) {
case TurnChoiceKind::Pass: throw NotReachableException();
case TurnChoiceKind::Attack: return ExecuteAttackChoice(choice.ForceAs<AttackTurnChoice>());
case TurnChoiceKind::Attack:
try_creature(return ExecuteAttackChoice(choice.ForceAs<AttackTurnChoice>()),
"Encountered exception during attack choice execution");
case TurnChoiceKind::Switch: return ExecuteSwitchChoice(choice.ForceAs<SwitchTurnChoice>());
case TurnChoiceKind::Flee: return ExecuteFleeChoice(choice.ForceAs<FleeTurnChoice>());

View File

@ -17,4 +17,12 @@ public:
___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
throw CreatureException(___ss.str());
#define try_creature(data, msg) \
try { \
data; \
} catch (const CreatureException& e) { \
throw e; \
} catch (const std::exception& e) { \
THROW_CREATURE(msg << ": '" << e.what() << "'."); \
}
#endif // CREATURELIB_CREATUREEXCEPTION_HPP