Skip to content

Commit

Permalink
don't throw an exception when server.cfg is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Jan 24, 2023
1 parent baf80ac commit d6de043
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/config_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ConfigReader::ConfigReader(const std::string& filename)

if (!file_.good())
{
throw std::runtime_error("Could not load configuration file " + filename + "!");
hasServerCfg_ = false;
}
else
{
hasServerCfg_ = true;
}
}
6 changes: 6 additions & 0 deletions src/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class ConfigReader
template <typename T>
T getValue(const std::string& key, T defaultValue)
{
if (!hasServerCfg_)
{
return defaultValue;
}

file_.clear();
file_.seekg(0, std::ios::beg);

Expand All @@ -38,4 +43,5 @@ class ConfigReader

private:
std::ifstream file_;
bool hasServerCfg_ = false;
};

0 comments on commit d6de043

Please sign in to comment.