From 7f716c7278d4f1322b19aaa5f61d57063be3db28 Mon Sep 17 00:00:00 2001 From: dongresource Date: Fri, 16 Oct 2020 21:47:43 +0200 Subject: [PATCH] Fixed exception usage in TableData. --- src/TableData.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/TableData.cpp b/src/TableData.cpp index 619a3c9..bb4cbc8 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -17,6 +17,15 @@ std::map TableData::RunningNPCRotations; std::map TableData::RunningNPCMapNumbers; std::map TableData::RunningMobs; +class TableException : public std::exception { +public: + std::string msg; + + TableException(std::string m) : std::exception() { msg = m; } + + const char *what() const throw() { return msg.c_str(); } +}; + void TableData::init() { int32_t nextId = 0; @@ -332,14 +341,12 @@ void TableData::loadDrops() { // Check if DropChance exists if (MobManager::MobDropChances.find(toAdd.dropChanceType) == MobManager::MobDropChances.end()) { - std::string errorMessage = " MobDropChance not found: " + std::to_string((toAdd.dropChanceType)); - throw (std::exception((errorMessage).c_str())); + throw TableException(" MobDropChance not found: " + std::to_string((toAdd.dropChanceType))); } // Check if number of crates is correct if (!(MobManager::MobDropChances[(int)drop["DropChance"]].cratesRatio.size() == toAdd.crateIDs.size())) { - std::string errorMessage = " DropType " + std::to_string((int)drop["DropType"]) + " contains invalid number of crates"; - throw (std::exception((errorMessage).c_str())); + throw TableException(" DropType " + std::to_string((int)drop["DropType"]) + " contains invalid number of crates"); } toAdd.taros = (int)drop["Taros"]; @@ -380,7 +387,7 @@ void TableData::loadDrops() { { char buff[255]; sprintf(buff, "Unknown item with Id %d and Type %d", (int)item["Id"], (int)item["Type"]); - throw (std::exception(buff)); + throw TableException(std::string(buff)); } std::map, Item>::iterator toAdd = ItemManager::ItemData.find(itemDataKey); // if item collection doesn't exist, start a new one