diff --git a/src/CSVReader/CSVReader.cpp b/src/CSVReader/CSVReader.cpp index 61622786fd2a17e68a4e61afa7d4a6c9218ff556..5e918c4f814c1d2b5b7e933bbce6347f9ecd9443 100644 --- a/src/CSVReader/CSVReader.cpp +++ b/src/CSVReader/CSVReader.cpp @@ -79,13 +79,18 @@ namespace lib4neuro { //TODO check empty values in data std::vector<double> input; for(auto ind : *input_col_indices) { - /* Check, if the string is a number */ - if(!std::regex_match( line.at(ind), std::regex( ( "((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ))) { - THROW_RUNTIME_ERROR(std::string("Value \"") + line.at(ind) + "\" is not numerical and so it cannot be used in Data Set!"); - } + try { + /* Check, if the string is a number */ + if(!std::regex_match( line.at(ind), std::regex( ( "((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?" ) ))) { + THROW_RUNTIME_ERROR(std::string("Value \"") + line.at(ind) + "\" is not numerical and so it cannot be used in Data Set!"); + } + + /* Add loaded number to the vector of inputs */ + input.push_back(std::stod(line.at(ind))); - /* Add loaded number to the vector of inputs */ - input.push_back(std::stod(line.at(ind))); + } catch(const std::out_of_range& e) { + THROW_OUT_OF_RANGE_ERROR("Non-existing index specified (" + std::to_string(ind) + ")!"); + } } std::vector<double> output;