From a9c80ef9dc6a1300a5963a0af51a5a0ac0a42052 Mon Sep 17 00:00:00 2001 From: Mavo Date: Tue, 16 Feb 2016 12:06:19 +0100 Subject: [PATCH] Better error handling Former-commit-id: 36bd1108226df7010e6749e4f989d4bdc8510336 --- src/parser/DFTGalileoParser.cpp | 23 ++++++++--------------- src/parser/DFTGalileoParser.h | 2 +- src/storage/dft/DFTBuilder.h | 9 +++++---- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/parser/DFTGalileoParser.cpp b/src/parser/DFTGalileoParser.cpp index c8639ae30..d11f5ae3b 100644 --- a/src/parser/DFTGalileoParser.cpp +++ b/src/parser/DFTGalileoParser.cpp @@ -15,14 +15,11 @@ namespace storm { template storm::storage::DFT DFTGalileoParser::parseDFT(const std::string& filename) { - if(readFile(filename)) { - storm::storage::DFT dft = builder.build(); - STORM_LOG_DEBUG("Elements:" << std::endl << dft.getElementsString()); - STORM_LOG_DEBUG("Spare Modules:" << std::endl << dft.getSpareModulesString()); - return dft; - } else { - throw storm::exceptions::FileIoException(); - } + readFile(filename); + storm::storage::DFT dft = builder.build(); + STORM_LOG_DEBUG("Elements:" << std::endl << dft.getElementsString()); + STORM_LOG_DEBUG("Spare Modules:" << std::endl << dft.getSpareModulesString()); + return dft; } template @@ -39,7 +36,7 @@ namespace storm { } template - bool DFTGalileoParser::readFile(const std::string& filename) { + void DFTGalileoParser::readFile(const std::string& filename) { // constants std::string toplevelToken = "toplevel"; std::string toplevelId; @@ -52,12 +49,11 @@ namespace storm { } catch (std::ifstream::failure e) { STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Exception during file opening on " << filename << "."); - return false; + return; } file.exceptions( std::ifstream::goodbit ); std::string line; - bool generalSuccess = true; while(std::getline(file, line)) { bool success = true; STORM_LOG_TRACE("Parsing: " << line); @@ -119,16 +115,13 @@ namespace storm { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Type name: " << tokens[1] << " not recognized."); success = false; } - } - if (generalSuccess) { - generalSuccess = success; + STORM_LOG_THROW(success, storm::exceptions::FileIoException, "Error while adding element '" << name << "' of line '" << line << "'."); } } if(!builder.setTopLevel(toplevelId)) { STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Top level id unknown."); } file.close(); - return generalSuccess; } template diff --git a/src/parser/DFTGalileoParser.h b/src/parser/DFTGalileoParser.h index 557803465..fc64ee80e 100644 --- a/src/parser/DFTGalileoParser.h +++ b/src/parser/DFTGalileoParser.h @@ -31,7 +31,7 @@ namespace storm { storm::storage::DFT parseDFT(std::string const& filename); private: - bool readFile(std::string const& filename); + void readFile(std::string const& filename); std::string stripQuotsFromName(std::string const& name); diff --git a/src/storage/dft/DFTBuilder.h b/src/storage/dft/DFTBuilder.h index ef01369c9..37c3c4eaa 100644 --- a/src/storage/dft/DFTBuilder.h +++ b/src/storage/dft/DFTBuilder.h @@ -6,6 +6,7 @@ #include #include #include +#include "src/utility/macros.h" namespace storm { namespace storage { @@ -70,7 +71,7 @@ namespace storm { //0 <= probability <= 1 if (!storm::utility::isOne(probability) && children.size() > 2) { //TODO Matthias: introduce additional element for probability and then add pdeps with probability 1 to children - std::cerr << "Probability != 1 for more than one child currently not supported." << std::endl; + STORM_LOG_ERROR("Probability != 1 for more than one child currently not supported."); return false; } @@ -78,7 +79,7 @@ namespace storm { std::string nameDep = name + "_" + std::to_string(i); if(mElements.count(nameDep) != 0) { // Element with that name already exists. - std::cerr << "Element with name: " << nameDep << " already exists." << std::endl; + STORM_LOG_ERROR("Element with name: " << nameDep << " already exists."); return false; } assert(storm::utility::isOne(probability) || children.size() == 2); @@ -92,7 +93,7 @@ namespace storm { bool addVotElement(std::string const& name, unsigned threshold, std::vector const& children) { assert(children.size() > 0); if(mElements.count(name) != 0) { - std::cerr << "Element with name: " << name << " already exists." << std::endl; + STORM_LOG_ERROR("Element with name: " << name << " already exists."); return false; } // It is an and-gate @@ -105,7 +106,7 @@ namespace storm { } if(threshold > children.size()) { - std::cerr << "Voting gates with threshold higher than the number of children is not supported." << std::endl; + STORM_LOG_ERROR("Voting gates with threshold higher than the number of children is not supported."); return false; } DFTElementPointer element = std::make_shared>(mNextId++, name, threshold);