Browse Source

Better error handling

Former-commit-id: 36bd110822
tempestpy_adaptions
Mavo 9 years ago
parent
commit
a9c80ef9dc
  1. 23
      src/parser/DFTGalileoParser.cpp
  2. 2
      src/parser/DFTGalileoParser.h
  3. 9
      src/storage/dft/DFTBuilder.h

23
src/parser/DFTGalileoParser.cpp

@ -15,14 +15,11 @@ namespace storm {
template<typename ValueType>
storm::storage::DFT<ValueType> DFTGalileoParser<ValueType>::parseDFT(const std::string& filename) {
if(readFile(filename)) {
storm::storage::DFT<ValueType> 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<ValueType> dft = builder.build();
STORM_LOG_DEBUG("Elements:" << std::endl << dft.getElementsString());
STORM_LOG_DEBUG("Spare Modules:" << std::endl << dft.getSpareModulesString());
return dft;
}
template<typename ValueType>
@ -39,7 +36,7 @@ namespace storm {
}
template<typename ValueType>
bool DFTGalileoParser<ValueType>::readFile(const std::string& filename) {
void DFTGalileoParser<ValueType>::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<typename ValueType>

2
src/parser/DFTGalileoParser.h

@ -31,7 +31,7 @@ namespace storm {
storm::storage::DFT<ValueType> 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);

9
src/storage/dft/DFTBuilder.h

@ -6,6 +6,7 @@
#include <iostream>
#include <unordered_map>
#include <map>
#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<std::string> 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<DFTVot<ValueType>>(mNextId++, name, threshold);

Loading…
Cancel
Save