From b3b96988316f006ec5c9629233e3d24d43807961 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 30 Jul 2020 20:15:27 +0200 Subject: [PATCH] More clearer exception messages. --- src/Battling/Flow/TurnHandler.cpp | 17 ++++++++--------- src/Library/Exceptions/CreatureException.hpp | 8 ++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) 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