catch config parse errors

This commit is contained in:
badaix 2016-02-03 23:03:30 +01:00
parent 5fae6e85f7
commit bfdca3038d

View file

@ -20,7 +20,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fstream> #include <fstream>
#include "common/log.h"
using namespace std; using namespace std;
@ -32,21 +32,28 @@ Config::Config()
filename_ = dir + "settings.json"; filename_ = dir + "settings.json";
cerr << filename_ << "\n"; cerr << filename_ << "\n";
ifstream ifs(filename_, std::ifstream::in); try
if (ifs.good())
{ {
json j; ifstream ifs(filename_, std::ifstream::in);
ifs >> j; if (ifs.good())
json jClient = j["Client"];
for (json::iterator it = jClient.begin(); it != jClient.end(); ++it)
{ {
ClientInfoPtr client = make_shared<ClientInfo>(); json j;
client->fromJson(*it); ifs >> j;
client->connected = false; json jClient = j["Client"];
clients.push_back(client); for (json::iterator it = jClient.begin(); it != jClient.end(); ++it)
std::cout << "Client:\n" << std::setw(4) << client->toJson() << '\n'; {
ClientInfoPtr client = make_shared<ClientInfo>();
client->fromJson(*it);
client->connected = false;
clients.push_back(client);
std::cout << "Client:\n" << std::setw(4) << client->toJson() << '\n';
}
} }
} }
catch(const std::exception& e)
{
logE << "Error reading config: " << e.what() << "\n";
}
} }