Skip to content

Commit

Permalink
abort -> throw
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang-ms committed Feb 22, 2024
1 parent 41e7c68 commit 8cc5712
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 40 deletions.
6 changes: 2 additions & 4 deletions moses2/FF/FeatureRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ void FeatureRegistry::Add(const std::string &name, FeatureFactory *factory)
std::pair<std::string, boost::shared_ptr<FeatureFactory> > to_ins(name,
boost::shared_ptr<FeatureFactory>(factory));
if (!registry_.insert(to_ins).second) {
cerr << "Duplicate feature name " << name << endl;
abort();
throw std::runtime_error("Duplicate feature name " + name);
}
}

Expand All @@ -98,8 +97,7 @@ FeatureFunction *FeatureRegistry::Construct(size_t startInd,
{
Map::const_iterator i = registry_.find(name);
if (i == registry_.end()) {
cerr << "Feature name " << name << " is not registered.";
abort();
throw std::runtime_error("Feature name " + name + " is not registered");
}
FeatureFactory *fact = i->second.get();
FeatureFunction *ff = fact->Create(startInd, line);
Expand Down
19 changes: 0 additions & 19 deletions moses2/HypothesisColl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,6 @@ StackAdd HypothesisColl::Add(const HypothesisBase *hypo)
const_cast<const HypothesisBase *&>(hypoExisting1);
hypoExisting2 = hypo;

/*
Delete(hypoExisting);
addRet = m_coll.insert(hypo);
UTIL_THROW_IF2(!addRet.second, "couldn't insert hypo "
<< hypo << "(" << hypo->hash() << ")");
*/
/*
if (!addRet.second) {
cerr << "couldn't insert hypo " << hypo << "(" << hypo->hash() << ")" << endl;
cerr << "m_coll=";
for (_HCType::const_iterator iter = m_coll.begin(); iter != m_coll.end(); ++iter) {
const HypothesisBase *h = *iter;
cerr << h << "(" << h->hash() << ") ";
}
cerr << endl;
abort();
}
*/

return StackAdd(true, hypoExisting);
} else {
// already storing the best hypo. discard incoming hypo
Expand Down
2 changes: 1 addition & 1 deletion moses2/System.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void System::IsPb()
isPb = false;
break;
default:
abort();
throw std::runtime_error("Unknown search algorithm " + options.search.algo);
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseT
if (system.isPb) {
//m_rootPb = new PBNODE();
} else {
abort();
throw std::runtime_error("Must be a phrase-based model");
//cerr << "m_rootSCFG=" << m_rootSCFG << endl;
}

Expand Down Expand Up @@ -108,15 +108,15 @@ void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseT

//cerr << "target=" << target->Debug(system) << endl;
} else {
abort();
throw std::runtime_error("Must be a phrase-based model");
}
}

if (system.isPb) {
m_rootPb.SortAndPrune(m_tableLimit, pool, system);
//cerr << "root=" << &m_rootPb << endl;
} else {
abort();
throw std::runtime_error("Must be a phrase-based model");
}
/*
BOOST_FOREACH(const PtMem::Node<Word>::Children::value_type &valPair, m_rootPb.GetChildren()) {
Expand Down Expand Up @@ -152,7 +152,7 @@ void DynamicPhraseTable::InitActiveChart(
const SCFG::Manager &mgr,
SCFG::InputPath &path) const
{
abort();
throw std::runtime_error("Must be a phrase-based model");
}

void DynamicPhraseTable::Lookup(MemPool &pool,
Expand All @@ -161,7 +161,7 @@ void DynamicPhraseTable::Lookup(MemPool &pool,
const SCFG::Stacks &stacks,
SCFG::InputPath &path) const
{
abort();
throw std::runtime_error("Must be a phrase-based model");
}

void DynamicPhraseTable::LookupGivenNode(
Expand All @@ -173,7 +173,7 @@ void DynamicPhraseTable::LookupGivenNode(
const Moses2::Range &subPhraseRange,
SCFG::InputPath &outPath) const
{
abort();
throw std::runtime_error("Must be a phrase-based model");
}

}
Expand Down
6 changes: 2 additions & 4 deletions util/file.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ namespace util {

scoped_fd::~scoped_fd() {
if (fd_ != -1 && close(fd_)) {
std::cerr << "Could not close file " << fd_ << std::endl;
std::abort();
throw std::runtime_error("Could not close file " + fd_);
}
}

void scoped_FILE_closer::Close(std::FILE *file) {
if (file && std::fclose(file)) {
std::cerr << "Could not close file " << file << std::endl;
std::abort();
throw std::runtime_error("Could not close file ");
}
}

Expand Down
3 changes: 1 addition & 2 deletions util/mmap.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ scoped_mmap::~scoped_mmap() {
SyncOrThrow(data_, size_);
UnmapOrThrow(data_, size_);
} catch (const util::ErrnoException &e) {
std::cerr << e.what();
abort();
throw std::runtime_error(e.what());
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions util/read_compressed.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ class GZip {

~GZip() {
if (Z_OK != inflateEnd(&stream_)) {
std::cerr << "zlib could not close properly." << std::endl;
abort();
throw std::runtime_error("zlib could not close properly.");
}
}

Expand Down Expand Up @@ -219,8 +218,7 @@ class BZip {
try {
HandleError(BZ2_bzDecompressEnd(&stream_));
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
abort();
throw std::runtime_error(e.what());
}
}

Expand Down

0 comments on commit 8cc5712

Please sign in to comment.