aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuarte Duarte <dnpd.dd@gmail.com>2015-02-15 14:56:12 +0000
committerDuarte Duarte <dnpd.dd@gmail.com>2015-02-22 06:09:01 +0000
commit958999ff5cc779e81b9a23789f84c292d79d1341 (patch)
treebd191d1a30c99f8ba526feb38899e7b4bd014575
parenta6505dd46a00c80b195cc924ed42e4174deb19b7 (diff)
Core/Server: Catch exceptions in int main()
The exceptions is rethrown on debug mode. Ref Coverity CID 1010213, 1022574, 1227501, 1227502, 1227503, 1227504, 1227505, 1254536 and 1254612 (cherry picked from commit e68ca82d4d039a401d03de145111b0a738bb9dd7) Conflicts: src/server/bnetserver/Main.cpp
-rw-r--r--src/server/authserver/Main.cpp20
-rw-r--r--src/server/worldserver/Main.cpp22
2 files changed, 39 insertions, 3 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index cd58ec2bf68..c57f8254d9c 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -58,7 +58,7 @@ boost::asio::deadline_timer _dbPingTimer(_ioService);
uint32 _dbPingInterval;
LoginDatabaseWorkerPool LoginDatabase;
-int main(int argc, char** argv)
+int mainImpl(int argc, char** argv)
{
std::string configFile = _TRINITY_REALM_CONFIG;
auto vm = GetConsoleArguments(argc, argv, configFile);
@@ -144,6 +144,24 @@ int main(int argc, char** argv)
return 0;
}
+/// Launch the Trinity server
+extern int main(int argc, char** argv)
+{
+ try
+ {
+ return mainImpl(argc, argv);
+ }
+ catch (std::exception& ex)
+ {
+ std::cerr << "Top-level exception caught:" << ex.what() << "\n";
+
+#ifndef NDEBUG // rethrow exception for the debugger
+ throw;
+#else
+ return 1;
+#endif
+ }
+}
/// Initialize connection to the database
bool StartDB()
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 7b47dba8759..06d8775440a 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -92,8 +92,7 @@ void ShutdownCLIThread(std::thread* cliThread);
void ShutdownThreadPool(std::vector<std::thread>& threadPool);
variables_map GetConsoleArguments(int argc, char** argv, std::string& cfg_file, std::string& cfg_service);
-/// Launch the Trinity server
-extern int main(int argc, char** argv)
+int mainImpl(int argc, char** argv)
{
std::string configFile = _TRINITY_CORE_CONFIG;
std::string configService;
@@ -289,6 +288,25 @@ extern int main(int argc, char** argv)
return World::GetExitCode();
}
+/// Launch the Trinity server
+extern int main(int argc, char** argv)
+{
+ try
+ {
+ return mainImpl(argc, argv);
+ }
+ catch (std::exception& ex)
+ {
+ std::cerr << "Top-level exception caught:" << ex.what() << "\n";
+
+#ifndef NDEBUG // rethrow exception for the debugger
+ throw;
+#else
+ return 1;
+#endif
+ }
+}
+
void ShutdownCLIThread(std::thread* cliThread)
{
if (cliThread != nullptr)