diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index b190142..5cbe132 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -14,14 +14,11 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr 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 choice) { switch (choiceKind) { case TurnChoiceKind::Pass: throw NotReachableException(); - case TurnChoiceKind::Attack: return ExecuteAttackChoice(choice.ForceAs()); + case TurnChoiceKind::Attack: + try_creature(return ExecuteAttackChoice(choice.ForceAs()), + "Encountered exception during attack choice execution"); case TurnChoiceKind::Switch: return ExecuteSwitchChoice(choice.ForceAs()); case TurnChoiceKind::Flee: return ExecuteFleeChoice(choice.ForceAs()); diff --git a/src/Library/Exceptions/CreatureException.hpp b/src/Library/Exceptions/CreatureException.hpp index 932a947..d78beb9 100644 --- a/src/Library/Exceptions/CreatureException.hpp +++ b/src/Library/Exceptions/CreatureException.hpp @@ -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