1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

get rid of global debug macros.

This commit is contained in:
AlexVinS
2015-02-14 22:42:47 +03:00
parent 7f12802407
commit aa5e9fc959
5 changed files with 35 additions and 40 deletions

View File

@@ -220,35 +220,6 @@ typedef boost::lock_guard<boost::recursive_mutex> TLockGuardRec;
#define ASSERT_IF_CALLED_WITH_PLAYER if(!player) {logGlobal->errorStream() << BOOST_CURRENT_FUNCTION; assert(0);} #define ASSERT_IF_CALLED_WITH_PLAYER if(!player) {logGlobal->errorStream() << BOOST_CURRENT_FUNCTION; assert(0);}
//XXX pls dont - 'debug macros' are usually more trouble than it's worth
#define HANDLE_EXCEPTION \
catch (const std::exception& e) { \
logGlobal->errorStream() << e.what(); \
throw; \
} \
catch (const std::exception * e) \
{ \
logGlobal->errorStream() << e->what(); \
throw; \
} \
catch (const std::string& e) { \
logGlobal->errorStream() << e; \
throw; \
}
#define HANDLE_EXCEPTIONC(COMMAND) \
catch (const std::exception& e) { \
COMMAND; \
logGlobal->errorStream() << e.what(); \
throw; \
} \
catch (const std::string &e) \
{ \
COMMAND; \
logGlobal->errorStream() << e; \
throw; \
}
// can be used for counting arrays // can be used for counting arrays
template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N]; template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
#define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) #define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr)))

View File

@@ -974,12 +974,17 @@ void CSelectionScreen::handleConnection()
upcomingPacks.push_back(pack); upcomingPacks.push_back(pack);
} }
} }
} HANDLE_EXCEPTION }
catch(int i) catch(int i)
{ {
if(i != 666) if(i != 666)
throw; throw;
} }
catch(...)
{
handleException();
throw;
}
} }
void CSelectionScreen::setSInfo(const StartInfo &si) void CSelectionScreen::setSInfo(const StartInfo &si)

View File

@@ -150,7 +150,11 @@ void CClient::waitForMoveAndSend(PlayerColor color)
logNetwork->debugStream() << "Wait for move thread was interrupted and no action will be send. Was a battle ended by spell?"; logNetwork->debugStream() << "Wait for move thread was interrupted and no action will be send. Was a battle ended by spell?";
return; return;
} }
HANDLE_EXCEPTION catch(...)
{
handleException();
return;
}
logNetwork->errorStream() << "We should not be here!"; logNetwork->errorStream() << "We should not be here!";
} }
@@ -787,7 +791,11 @@ void CClient::commenceTacticPhaseForInt(shared_ptr<CBattleGameInterface> battleI
MakeAction ma(BattleAction::makeEndOFTacticPhase(gs->curB->playerToSide(battleInt->playerID))); MakeAction ma(BattleAction::makeEndOFTacticPhase(gs->curB->playerToSide(battleInt->playerID)));
sendRequest(&ma, battleInt->playerID); sendRequest(&ma, battleInt->playerID);
} }
} HANDLE_EXCEPTION }
catch(...)
{
handleException();
}
} }
void CClient::invalidatePaths() void CClient::invalidatePaths()
@@ -964,7 +972,13 @@ CServerHandler::CServerHandler(bool runServer /*= false*/)
try try
{ {
shared = new SharedMem(); shared = new SharedMem();
} HANDLE_EXCEPTIONC(logNetwork->errorStream() << "Cannot open interprocess memory: ";) }
catch(...)
{
logNetwork->error("Cannot open interprocess memory.");
handleException();
throw;
}
#endif #endif
} }

View File

@@ -40,17 +40,17 @@ DLL_LINKAGE void preinitDLL(CConsoleHandler *Console)
{ {
VLC->loadFilesystem(); VLC->loadFilesystem();
} }
HANDLE_EXCEPTION; catch(...)
{
handleException();
throw;
}
} }
DLL_LINKAGE void loadDLLClasses() DLL_LINKAGE void loadDLLClasses()
{
//try
{ {
VLC->init(); VLC->init();
} }
//HANDLE_EXCEPTION;
}
const IBonusTypeHandler * LibClasses::getBth() const const IBonusTypeHandler * LibClasses::getBth() const
{ {

View File

@@ -942,7 +942,12 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
logGlobal->errorStream() << e.what(); logGlobal->errorStream() << e.what();
end2 = true; end2 = true;
} }
HANDLE_EXCEPTION(end2 = true); catch(...)
{
end2 = true;
handleException();
throw;
}
logGlobal->errorStream() << "Ended handling connection"; logGlobal->errorStream() << "Ended handling connection";
} }