Exit is better than abort.

Also use a macro instead of integer to indicate failure.
This commit is contained in:
Tiago Gomes 2012-12-20 17:37:59 +00:00
parent 2ca31ca14a
commit 053fa31bb2
9 changed files with 24 additions and 25 deletions

View File

@ -116,7 +116,7 @@ ElimGraph::exportToGraphViz (
out << " [shape=box3d]" << endl; out << " [shape=box3d]" << endl;
} else { } else {
cout << "error: invalid variable id: " << highlightVarIds[i] << endl; cout << "error: invalid variable id: " << highlightVarIds[i] << endl;
abort(); exit (EXIT_FAILURE);
} }
} }
for (size_t i = 0; i < nodes_.size(); i++) { for (size_t i = 0; i < nodes_.size(); i++) {

View File

@ -38,14 +38,14 @@ FactorGraph::readFromUaiFormat (const char* fileName)
std::ifstream is (fileName); std::ifstream is (fileName);
if (!is.is_open()) { if (!is.is_open()) {
cerr << "error: cannot read from file " << fileName << endl; cerr << "error: cannot read from file " << fileName << endl;
abort(); exit (EXIT_FAILURE);
} }
ignoreLines (is); ignoreLines (is);
string line; string line;
getline (is, line); getline (is, line);
if (line != "MARKOV") { if (line != "MARKOV") {
cerr << "error: the network must be a MARKOV network " << endl; cerr << "error: the network must be a MARKOV network " << endl;
abort(); exit (EXIT_FAILURE);
} }
// read the number of vars // read the number of vars
ignoreLines (is); ignoreLines (is);
@ -74,7 +74,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
cerr << "error: invalid variable identifier `" << vid << "'" << endl; cerr << "error: invalid variable identifier `" << vid << "'" << endl;
cerr << "identifiers must be between 0 and " << ranges.size() - 1 ; cerr << "identifiers must be between 0 and " << ranges.size() - 1 ;
cerr << endl; cerr << endl;
abort(); exit (EXIT_FAILURE);
} }
factorVarIds.back().push_back (vid); factorVarIds.back().push_back (vid);
factorRanges.back().push_back (ranges[vid]); factorRanges.back().push_back (ranges[vid]);
@ -89,7 +89,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
cerr << "error: invalid number of parameters for factor nº " << i ; cerr << "error: invalid number of parameters for factor nº " << i ;
cerr << ", expected: " << Util::sizeExpected (factorRanges[i]); cerr << ", expected: " << Util::sizeExpected (factorRanges[i]);
cerr << ", given: " << nrParams << endl; cerr << ", given: " << nrParams << endl;
abort(); exit (EXIT_FAILURE);
} }
Params params (nrParams); Params params (nrParams);
for (unsigned j = 0; j < nrParams; j++) { for (unsigned j = 0; j < nrParams; j++) {
@ -111,7 +111,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
std::ifstream is (fileName); std::ifstream is (fileName);
if (!is.is_open()) { if (!is.is_open()) {
cerr << "error: cannot read from file " << fileName << endl; cerr << "error: cannot read from file " << fileName << endl;
abort(); exit (EXIT_FAILURE);
} }
ignoreLines (is); ignoreLines (is);
unsigned nrFactors; unsigned nrFactors;

View File

@ -26,7 +26,7 @@ main (int argc, const char* argv[])
if (argc <= 1) { if (argc <= 1) {
cerr << "error: no graphical model specified" << endl; cerr << "error: no graphical model specified" << endl;
cerr << USAGE << endl; cerr << USAGE << endl;
exit (0); exit (EXIT_FAILURE);
} }
int idx = readHorusFlags (argc, argv); int idx = readHorusFlags (argc, argv);
FactorGraph fg; FactorGraph fg;
@ -53,12 +53,12 @@ readHorusFlags (int argc, const char* argv[])
if (leftArg.empty()) { if (leftArg.empty()) {
cerr << "error: missing left argument" << endl; cerr << "error: missing left argument" << endl;
cerr << USAGE << endl; cerr << USAGE << endl;
exit (0); exit (EXIT_FAILURE);
} }
if (rightArg.empty()) { if (rightArg.empty()) {
cerr << "error: missing right argument" << endl; cerr << "error: missing right argument" << endl;
cerr << USAGE << endl; cerr << USAGE << endl;
exit (0); exit (EXIT_FAILURE);
} }
Util::setHorusFlag (leftArg, rightArg); Util::setHorusFlag (leftArg, rightArg);
} }
@ -79,7 +79,7 @@ readFactorGraph (FactorGraph& fg, const char* s)
} else { } else {
cerr << "error: the graphical model must be defined either " ; cerr << "error: the graphical model must be defined either " ;
cerr << "in a UAI or libDAI file" << endl; cerr << "in a UAI or libDAI file" << endl;
exit (0); exit (EXIT_FAILURE);
} }
} }
@ -100,14 +100,14 @@ readQueryAndEvidence (
cerr << "error: `" << arg << "' " ; cerr << "error: `" << arg << "' " ;
cerr << "is not a variable id" ; cerr << "is not a variable id" ;
cerr << endl; cerr << endl;
exit (0); exit (EXIT_FAILURE);
} }
VarId vid = Util::stringToUnsigned (arg); VarId vid = Util::stringToUnsigned (arg);
VarNode* queryVar = fg.getVarNode (vid); VarNode* queryVar = fg.getVarNode (vid);
if (queryVar == false) { if (queryVar == false) {
cerr << "error: unknow variable with id " ; cerr << "error: unknow variable with id " ;
cerr << "`" << vid << "'" << endl; cerr << "`" << vid << "'" << endl;
exit (0); exit (EXIT_FAILURE);
} }
queryIds.push_back (vid); queryIds.push_back (vid);
} else { } else {
@ -117,37 +117,36 @@ readQueryAndEvidence (
if (leftArg.empty()) { if (leftArg.empty()) {
cerr << "error: missing left argument" << endl; cerr << "error: missing left argument" << endl;
cerr << USAGE << endl; cerr << USAGE << endl;
exit (0); exit (EXIT_FAILURE);
} }
if (Util::isInteger (leftArg) == false) { if (Util::isInteger (leftArg) == false) {
cerr << "error: `" << leftArg << "' " ; cerr << "error: `" << leftArg << "' " ;
cerr << "is not a variable id" << endl ; cerr << "is not a variable id" << endl ;
exit (0); exit (EXIT_FAILURE);
continue;
} }
VarId vid = Util::stringToUnsigned (leftArg); VarId vid = Util::stringToUnsigned (leftArg);
VarNode* observedVar = fg.getVarNode (vid); VarNode* observedVar = fg.getVarNode (vid);
if (observedVar == false) { if (observedVar == false) {
cerr << "error: unknow variable with id " ; cerr << "error: unknow variable with id " ;
cerr << "`" << vid << "'" << endl; cerr << "`" << vid << "'" << endl;
exit (0); exit (EXIT_FAILURE);
} }
if (rightArg.empty()) { if (rightArg.empty()) {
cerr << "error: missing right argument" << endl; cerr << "error: missing right argument" << endl;
cerr << USAGE << endl; cerr << USAGE << endl;
exit (0); exit (EXIT_FAILURE);
} }
if (Util::isInteger (rightArg) == false) { if (Util::isInteger (rightArg) == false) {
cerr << "error: `" << rightArg << "' " ; cerr << "error: `" << rightArg << "' " ;
cerr << "is not a state index" << endl ; cerr << "is not a state index" << endl ;
exit (0); exit (EXIT_FAILURE);
} }
unsigned stateIdx = Util::stringToUnsigned (rightArg); unsigned stateIdx = Util::stringToUnsigned (rightArg);
if (observedVar->isValidState (stateIdx) == false) { if (observedVar->isValidState (stateIdx) == false) {
cerr << "error: `" << stateIdx << "' " ; cerr << "error: `" << stateIdx << "' " ;
cerr << "is not a valid state index for variable with id " ; cerr << "is not a valid state index for variable with id " ;
cerr << "`" << vid << "'" << endl; cerr << "`" << vid << "'" << endl;
exit (0); exit (EXIT_FAILURE);
} }
observedVar->setEvidence (stateIdx); observedVar->setEvidence (stateIdx);
} }

View File

@ -424,7 +424,7 @@ readParfactor (YAP_Term pfTerm)
YAP_Term ti = YAP_ArgOfTerm (i, term); YAP_Term ti = YAP_ArgOfTerm (i, term);
if (YAP_IsAtomTerm (ti) == false) { if (YAP_IsAtomTerm (ti) == false) {
cerr << "error: constraint has free variables" << endl; cerr << "error: constraint has free variables" << endl;
abort(); exit (EXIT_FAILURE);
} }
string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti))); string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti)));
tuple[i - 1] = LiftedUtils::getSymbol (name); tuple[i - 1] = LiftedUtils::getSymbol (name);

View File

@ -23,7 +23,7 @@ LiftedKc::solveQuery (const Grounds& query)
circuit_ = new LiftedCircuit (lwcnf_); circuit_ = new LiftedCircuit (lwcnf_);
if (circuit_->isCompilationSucceeded() == false) { if (circuit_->isCompilationSucceeded() == false) {
cerr << "error: compilation failed" << endl; cerr << "error: compilation failed" << endl;
abort(); exit (EXIT_FAILURE);
} }
vector<PrvGroup> groups; vector<PrvGroup> groups;
Ranges ranges; Ranges ranges;

View File

@ -37,7 +37,7 @@ LiftedOperations::shatterAgainstQuery (
if (found == false) { if (found == false) {
cerr << "error: could not find a parfactor with ground " ; cerr << "error: could not find a parfactor with ground " ;
cerr << "`" << query[i] << "'" << endl; cerr << "`" << query[i] << "'" << endl;
exit (0); exit (EXIT_FAILURE);
} }
pfList.add (newPfs); pfList.add (newPfs);
} }

View File

@ -691,7 +691,7 @@ Parfactor::expandPotential (
if (newSize > params_.max_size()) { if (newSize > params_.max_size()) {
cerr << "error: an overflow occurred when performing expansion" ; cerr << "error: an overflow occurred when performing expansion" ;
cerr << endl; cerr << endl;
abort(); exit (EXIT_FAILURE);
} }
Params backup = params_; Params backup = params_;

View File

@ -336,7 +336,7 @@ ParfactorList::shatterAgainstMySelf (
if (f1.isAtom()) { if (f1.isAtom()) {
cerr << "error: a ground occurs twice in a parfactor" << endl; cerr << "error: a ground occurs twice in a parfactor" << endl;
cerr << endl; cerr << endl;
abort(); exit (EXIT_FAILURE);
} }
assert (g->constr()->empty() == false); assert (g->constr()->empty() == false);
ConstraintTree ctCopy (*g->constr()); ConstraintTree ctCopy (*g->constr());

View File

@ -54,7 +54,7 @@ stringToUnsigned (string str)
ss >> val; ss >> val;
if (val < 0) { if (val < 0) {
cerr << "error: the readed number is negative" << endl; cerr << "error: the readed number is negative" << endl;
abort(); exit (EXIT_FAILURE);
} }
return static_cast<unsigned> (val); return static_cast<unsigned> (val);
} }