From 68e1a87b7dd94b886b48ca7816117d02d1954a22 Mon Sep 17 00:00:00 2001 From: Giovanna Lazzari Miotto <giovanna.lazzari.miotto@cern.ch> Date: Tue, 5 Dec 2023 01:10:00 +0100 Subject: [PATCH] [config] Throw custom exceptions --- src/config.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config.cc b/src/config.cc index 9456345c..4ac5ab38 100644 --- a/src/config.cc +++ b/src/config.cc @@ -2,19 +2,18 @@ #include <fstream> +#include "exception.h" #include "log.h" config::config(std::string filename) { bool valid = true; - - std::ifstream in(filename.c_str(), std::ios_base::in); + std::ifstream in(filename, std::ios_base::in); if (!in.is_open()) { - throw std::invalid_argument("Configuration file could not be opened. Does it exist?"); + THROW(FileException, "Configuration file could not be opened. Does it exist?"); } - std::string line; - while (!std::getline(in, line).eof()) { + for (std::string line; std::getline(in, line);) { // Perform left trim line.erase(line.begin(), std::find_if(line.begin(), line.end(), [](int ch) { return !std::isspace(ch); })); @@ -52,9 +51,10 @@ config::config(std::string filename) { } if (!valid) { - throw std::invalid_argument("Configuration error: Keys with no value detected!"); + THROW(ParseException, "Configuration error: Keys with no value detected!"); } } + void config::print() const { for (std::map<std::string, std::string>::const_iterator it = vmap.begin(); it != vmap.end(); it++) { -- GitLab