diff --git a/src/exceptions/InvalidSettings.h b/src/exceptions/InvalidSettings.h new file mode 100644 index 000000000..8244c6d4c --- /dev/null +++ b/src/exceptions/InvalidSettings.h @@ -0,0 +1,35 @@ +#ifndef MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ +#define MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ + +#include + +namespace mrmc { +namespace exceptions { + +//!This exception is thrown when a memory request can't be +//!fulfilled. +class InvalidSettings : public std::exception +{ + public: +/* The Visual C++-Version of the exception class has constructors accepting + * a char*-constant; The GCC version does not have these + * + * As the "extended" constructor is used in the sparse matrix code, a dummy + * constructor is used under linux (which will ignore the parameter) + */ +#ifdef _WIN32 + InvalidSettings() : exception("::mrmc::InvalidSettings"){} + InvalidSettings(const char * const s): exception(s) {} +#else + InvalidSettings() : exception() {} + InvalidSettings(const char * const s): exception() {} + +#endif + virtual const char* what() const throw() + { return "mrmc::InvalidSettings"; } +}; + +} // namespace exceptions +} // namespace mrmc + +#endif // MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ diff --git a/src/mrmc-cpp.cpp b/src/mrmc-cpp.cpp index 1a84a4ed9..2de514550 100644 --- a/src/mrmc-cpp.cpp +++ b/src/mrmc-cpp.cpp @@ -30,27 +30,39 @@ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = "mrmc-cpp" #include "src/parser/read_tra_file.h" #include "src/utility/settings.h" #include "Eigen/Sparse" + +#include "src/exceptions/InvalidSettings.h" int main(const int argc, const char* argv[]) { // Logging init pantheios_be_file_setFilePath("log.all"); pantheios::log_INFORMATIONAL("MRMC-Cpp started."); - - mrmc::settings::Settings s(argc, argv, NULL); - if (s.isSet("help")) + mrmc::settings::Settings* s = NULL; + + try + { + s = new mrmc::settings::Settings(argc, argv, NULL); + } + catch (mrmc::exceptions::InvalidSettings) + { + std::cout << "Could not recover from settings error, terminating." << std::endl; + return 1; + } + + if (s->isSet("help")) { - std::cout << s.getHelpForCommandline() << std::endl; + std::cout << s->getHelpForCommandline() << std::endl; return 0; } - if (s.isSet("help-config")) + if (s->isSet("help-config")) { - std::cout << s.getHelpForConfigfile() << std::endl; + std::cout << s->getHelpForConfigfile() << std::endl; return 0; } - mrmc::sparse::StaticSparseMatrix* probMatrix = mrmc::parser::read_tra_file(s.getString("trafile").c_str()); - mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s.getString("labfile").c_str()); + mrmc::sparse::StaticSparseMatrix* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str()); + mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s->getString("labfile").c_str()); mrmc::models::Dtmc dtmc(probMatrix, labeling); diff --git a/src/utility/settings.h b/src/utility/settings.h index beca43cc5..991862f0b 100644 --- a/src/utility/settings.h +++ b/src/utility/settings.h @@ -10,6 +10,7 @@ #include #include +#include "src/exceptions/InvalidSettings.h" namespace mrmc { namespace settings { @@ -95,7 +96,11 @@ namespace settings { } catch (bpo::required_option e) { - std::cout << e.what() << std::endl; + if (! (this->vm.count("help") || this->vm.count("help-config"))) + { + std::cout << e.what() << std::endl; + throw mrmc::exceptions::InvalidSettings(); + } } catch (bpo::error e) {