feat: catch exceptions in readConfig

This commit is contained in:
3lswear
2022-02-13 22:45:56 +03:00
parent a230ca2639
commit eaaa126e97

View File

@@ -36,8 +36,30 @@ void Server::print_epoll_events(unsigned int events)
//----------------------------------------------Configuration-----------------------------------------------------------------------------------
void Server::readConfig(char *filename)
{
TOMLMap *root = parse(filename);
TOMLMap *root = NULL;
try
{
root = parse(filename);
}
catch (config::Tokenizer::NoMoreTokens &e)
{
std::cerr << RED << "FATAL: ";
std::cerr << e.what() << RESET << std::endl;
// root->clear();
// delete root;
// clean_parsed(root);
return;
}
catch (config::Tokenizer::InvalidToken &e)
{
std::cerr << RED << "FATAL: ";
std::cerr << e.what() << RESET << std::endl;
// clean_parsed(root);
// root->clear();
delete root;
return;
}
/* TOMLMap *map; */
TOMLMap::iterator it1;
@@ -408,9 +430,9 @@ void Server::clean_parsed(TOMLMap *root)
DBOUT << ">>> cleaning up: <<<" << std::endl;
for (it = root->begin(); it != root->end(); ++it)
{
/* DBOUT << RED << it->first */
/* << ": " << GREEN */
/* << *(it->second->toString()); */
DBOUT << RED << it->first
<< ": " << GREEN
<< *(it->second->toString());
clean_generic(it->second);
/* delete it->second; */