diff --git a/src/cpp/benders/benders_core/SimulationOptions.cpp b/src/cpp/benders/benders_core/SimulationOptions.cpp index 13cbe07b5..90a8ff9ba 100644 --- a/src/cpp/benders/benders_core/SimulationOptions.cpp +++ b/src/cpp/benders/benders_core/SimulationOptions.cpp @@ -5,15 +5,17 @@ #include #include "LogUtils.h" -Json::Value get_value_from_json(const std::filesystem::path &file_name) { +Json::Value SimulationOptions::get_value_from_json( + const std::filesystem::path &file_name) { Json::Value _input; std::ifstream input_file_l(file_name, std::ifstream::binary); Json::CharReaderBuilder builder_l; std::string errs; if (!parseFromStream(builder_l, input_file_l, &_input, &errs)) { - std::cerr << LOGLOCATION << "Invalid options file: " << file_name << "\n" - << errs; - std::exit(1); + using namespace std::string_literals; + auto message = LOGLOCATION + "Invalid options file: "s + file_name.string() + + "\n" + errs; + throw InvalidOptionFileException(message); } return _input; } @@ -171,6 +173,10 @@ BendersBaseOptions SimulationOptions::get_benders_options() const { return result; } +SimulationOptions::InvalidOptionFileException::InvalidOptionFileException( + const std::string &arg) + : runtime_error(arg) {} + ExternalLoopOptions SimulationOptions::GetExternalLoopOptions() const { return {EXT_LOOP_CRITERION_VALUE, EXT_LOOP_CRITERION_TOLERANCE, diff --git a/src/cpp/benders/benders_core/include/SimulationOptions.h b/src/cpp/benders/benders_core/include/SimulationOptions.h index 5d9c9316f..1d9630e50 100644 --- a/src/cpp/benders/benders_core/include/SimulationOptions.h +++ b/src/cpp/benders/benders_core/include/SimulationOptions.h @@ -24,4 +24,10 @@ class SimulationOptions { private: void set_weights(); + Json::Value get_value_from_json(const std::filesystem::path &file_name); + + class InvalidOptionFileException : public std::runtime_error { + public: + explicit InvalidOptionFileException(const std::string &arg); + }; };