diff --git a/moses/ChartHypothesisCollection.cpp b/moses/ChartHypothesisCollection.cpp index 49657f4ef..8a4a48a29 100644 --- a/moses/ChartHypothesisCollection.cpp +++ b/moses/ChartHypothesisCollection.cpp @@ -108,8 +108,7 @@ bool ChartHypothesisCollection::AddHypothesis(ChartHypothesis *hypo, ChartManage bool added = Add(hypo, manager).second; if (!added) { iterExisting = m_hypos.find(hypo); - TRACE_ERR("Offending hypo = " << **iterExisting << endl); - abort(); + UTIL_THROW2("Offending hypo = " << **iterExisting); } return false; } else { diff --git a/moses/ConfusionNet.cpp b/moses/ConfusionNet.cpp index a6b93a2dc..dd2ac8795 100644 --- a/moses/ConfusionNet.cpp +++ b/moses/ConfusionNet.cpp @@ -242,8 +242,7 @@ void ConfusionNet::Print(std::ostream& out) const #endif Phrase ConfusionNet::GetSubString(const WordsRange&) const { - TRACE_ERR("ERROR: call to ConfusionNet::GetSubString\n"); - abort(); + UTIL_THROW2("ERROR: call to ConfusionNet::GetSubString\n"); //return Phrase(Input); } @@ -257,8 +256,7 @@ std::string ConfusionNet::GetStringRep(const std::vector /* factorsT #endif const Word& ConfusionNet::GetWord(size_t) const { - TRACE_ERR("ERROR: call to ConfusionNet::GetFactorArray\n"); - abort(); + UTIL_THROW2("ERROR: call to ConfusionNet::GetFactorArray\n"); } #ifdef _WIN32 #pragma warning(default:4716) diff --git a/moses/File.h b/moses/File.h index ef407d047..4411efb97 100644 --- a/moses/File.h +++ b/moses/File.h @@ -9,6 +9,7 @@ #include #include +#include #include #include "util/exception.hh" #include "UserMessage.h" @@ -37,8 +38,7 @@ static const OFF_T InvalidOffT=-1; template inline size_t fWrite(FILE* f,const T& t) { if(fwrite(&t,sizeof(t),1,f)!=1) { - TRACE_ERR("ERROR:: fwrite!\n"); - abort(); + UTIL_THROW2("ERROR:: fwrite!"); } return sizeof(t); } @@ -46,8 +46,7 @@ template inline size_t fWrite(FILE* f,const T& t) template inline void fRead(FILE* f,T& t) { if(fread(&t,sizeof(t),1,f)!=1) { - TRACE_ERR("ERROR: fread!\n"); - abort(); + UTIL_THROW2("ERROR: fread!"); } } @@ -56,8 +55,7 @@ template inline size_t fWrite(FILE* f,const T* b,const T* e) UINT32 s=std::distance(b,e); size_t rv=fWrite(f,s); if(fwrite(b,sizeof(T),s,f)!=s) { - TRACE_ERR("ERROR: fwrite!\n"); - abort(); + UTIL_THROW2("ERROR: fwrite!"); } return rv+sizeof(T)*s; } @@ -67,8 +65,7 @@ template inline size_t fWrite(FILE* f,const T b,const T e) UINT32 s=std::distance(b,e); size_t rv=fWrite(f,s); if(fwrite(&(*b),sizeof(T),s,f)!=s) { - TRACE_ERR("ERROR: fwrite!\n"); - abort(); + UTIL_THROW2("ERROR: fwrite!"); } return rv+sizeof(T)*s; } @@ -78,8 +75,7 @@ template inline size_t fWriteVector(FILE* f,const C& v) UINT32 s=v.size(); size_t rv=fWrite(f,s); if(fwrite(&v[0],sizeof(typename C::value_type),s,f)!=s) { - TRACE_ERR("ERROR: fwrite!\n"); - abort(); + UTIL_THROW2("ERROR: fwrite!"); } return rv+sizeof(typename C::value_type)*s; } @@ -91,8 +87,7 @@ template inline void fReadVector(FILE* f, C& v) v.resize(s); size_t r=fread(&(*v.begin()),sizeof(typename C::value_type),s,f); if(r!=s) { - TRACE_ERR("ERROR: freadVec! "<(line, file, factorType, lazy); } - } catch (std::exception &e) { - std::cerr << e.what() << std::endl; - abort(); - } } } diff --git a/moses/LM/LDHT.cpp b/moses/LM/LDHT.cpp index ed118a7c2..61226208c 100644 --- a/moses/LM/LDHT.cpp +++ b/moses/LM/LDHT.cpp @@ -322,14 +322,12 @@ void LanguageModelLDHT::IssueRequestsFor(Hypothesis& hypo, LDHTLMState* new_state = new LDHTLMState(); if (input_state == NULL) { if (hypo.GetCurrTargetWordsRange().GetStartPos() != 0) { - V("got a null state but not at start of sentence"); - abort(); + UTIL_THROW2("got a null state but not at start of sentence"); } new_state->gram_fingerprints.appendGram(BOS_); } else { if (hypo.GetCurrTargetWordsRange().GetStartPos() == 0) { - V("got a non null state but at start of sentence"); - abort(); + UTIL_THROW2("got a non null state but at start of sentence"); } new_state->copyFrom(static_cast(*input_state)); } diff --git a/moses/PDTAimp.h b/moses/PDTAimp.h index 2fda02e03..2e6f6b7e2 100644 --- a/moses/PDTAimp.h +++ b/moses/PDTAimp.h @@ -228,8 +228,7 @@ public: std::string binFname=filePath+".binphr.idx"; if(!FileExists(binFname.c_str())) { - UserMessage::Add( "bin ttable does not exist\n"); - abort(); + UTIL_THROW2( "bin ttable does not exist"); //TRACE_ERR( "bin ttable does not exist -> create it\n"); //InputFileStream in(filePath); //m_dict->Create(in,filePath); diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index 262d28134..860eb8a78 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -726,7 +726,7 @@ void Parameter::ConvertWeightArgsLM() newFeatureName = "KENLM"; break; default: - abort(); + UTIL_THROW2("Unkown language model type id:" << lmType); } size_t numFF = 1; diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 20ddcf79f..68287296f 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -100,11 +100,12 @@ private: static IndexPair GetIndexes(const FeatureFunction* sp) { ScoreIndexMap::const_iterator indexIter = s_scoreIndexes.find(sp); if (indexIter == s_scoreIndexes.end()) { - std::cerr << "ERROR: FeatureFunction: " << sp->GetScoreProducerDescription() << + std::stringstream strme; + strme << "ERROR: FeatureFunction: " << sp->GetScoreProducerDescription() << " not registered with ScoreIndexMap" << std::endl; - std::cerr << "You must call ScoreComponentCollection.RegisterScoreProducer() " << + strme << "You must call ScoreComponentCollection.RegisterScoreProducer() " << " for every FeatureFunction" << std::endl; - abort(); + UTIL_THROW2(strme.str()); } return indexIter->second; } diff --git a/moses/Search.cpp b/moses/Search.cpp index 54b3c91de..030071021 100644 --- a/moses/Search.cpp +++ b/moses/Search.cpp @@ -30,8 +30,7 @@ Search *Search::CreateSearch(Manager& manager, const InputType &source, case NormalBatch: return new SearchNormalBatch(manager, source, transOptColl); default: - UserMessage::Add("ERROR: search. Aborting\n"); - abort(); + UTIL_THROW2("ERROR: search. Aborting\n"); return NULL; } } diff --git a/moses/SearchNormalBatch.cpp b/moses/SearchNormalBatch.cpp index 8d3fbd023..244ebbf05 100644 --- a/moses/SearchNormalBatch.cpp +++ b/moses/SearchNormalBatch.cpp @@ -140,8 +140,7 @@ ExpandHypothesis(const Hypothesis &hypothesis, } m_partial_hypos.push_back(newHypo); } else { - std::cerr << "can't use early discarding with batch decoding!" << std::endl; - abort(); + UTIL_THROW2("can't use early discarding with batch decoding!"); } } diff --git a/moses/TranslationModel/CompactPT/BlockHashIndex.cpp b/moses/TranslationModel/CompactPT/BlockHashIndex.cpp index ff0ca67be..cd277ad0c 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.cpp +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.cpp @@ -366,10 +366,11 @@ void BlockHashIndex::CalcHash(size_t current, void* source_void) if(lastKey > temp) { if(source->nkeys != 2 || temp != "###DUMMY_KEY###") { - std::cerr << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; - std::cerr << "1: " << lastKey << std::endl; - std::cerr << "2: " << temp << std::endl; - abort(); + std::stringstream strme; + strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; + strme << "1: " << lastKey << std::endl; + strme << "2: " << temp << std::endl; + UTIL_THROW2(strme.str()); } } lastKey = temp; diff --git a/moses/TranslationModel/CompactPT/BlockHashIndex.h b/moses/TranslationModel/CompactPT/BlockHashIndex.h index f090719a2..bb5888e30 100644 --- a/moses/TranslationModel/CompactPT/BlockHashIndex.h +++ b/moses/TranslationModel/CompactPT/BlockHashIndex.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #define moses_BlockHashIndex_h #include +#include #include #include #include @@ -140,10 +141,11 @@ public: size_t current = m_landmarks.size(); if(m_landmarks.size() && m_landmarks.back().str() >= keys[0]) { - std::cerr << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; - std::cerr << "1: " << m_landmarks.back().str() << std::endl; - std::cerr << "2: " << keys[0] << std::endl; - abort(); + std::stringstream strme; + strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort" << std::endl; + strme << "1: " << m_landmarks.back().str() << std::endl; + strme << "2: " << keys[0] << std::endl; + UTIL_THROW2(strme.str()); } m_landmarks.push_back(keys[0]); diff --git a/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp b/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp index a6e6b358c..c4ba1084d 100644 --- a/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp +++ b/moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.cpp @@ -19,6 +19,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ +#include #include "LexicalReorderingTableCreator.h" #include "ThrowingFwrite.h" #include "moses/Util.h" @@ -203,10 +204,11 @@ std::string LexicalReorderingTableCreator::EncodeLine(std::vector& } if(m_numScoreComponent != scores.size()) { - std::cerr << "Error: Wrong number of scores detected (" + std::stringstream strme; + strme << "Error: Wrong number of scores detected (" << scores.size() << " != " << m_numScoreComponent << ") :" << std::endl; - std::cerr << "Line: " << tokens[0] << " ||| ... ||| " << scoresString << std::endl; - abort(); + strme << "Line: " << tokens[0] << " ||| ... ||| " << scoresString << std::endl; + UTIL_THROW2(strme.str()); } size_t c = 0; diff --git a/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp b/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp index b3389c63f..30f43a4fe 100644 --- a/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp +++ b/moses/TranslationModel/CompactPT/PhraseTableCreator.cpp @@ -714,10 +714,11 @@ std::string PhraseTableCreator::EncodeLine(std::vector& tokens, siz std::vector scores = Tokenize(scoresStr); if(scores.size() != m_numScoreComponent) { - std::cerr << "Error: Wrong number of scores detected (" + std::stringstream strme; + strme << "Error: Wrong number of scores detected (" << scores.size() << " != " << m_numScoreComponent << ") :" << std::endl; - std::cerr << "Line: " << tokens[0] << " ||| " << tokens[1] << " ||| " << tokens[3] << " ..." << std::endl; - abort(); + strme << "Line: " << tokens[0] << " ||| " << tokens[1] << " ||| " << tokens[3] << " ..." << std::endl; + UTIL_THROW2(strme.str()); } std::set a; @@ -1039,27 +1040,30 @@ void RankingTask::operator()() *it = Moses::Trim(*it); if(tokens.size() < 4) { - std::cerr << "Error: It seems the following line has a wrong format:" << std::endl; - std::cerr << "Line " << i << ": " << lines[i] << std::endl; - abort(); + std::stringstream strme; + strme << "Error: It seems the following line has a wrong format:" << std::endl; + strme << "Line " << i << ": " << lines[i] << std::endl; + UTIL_THROW2(strme.str()); } if(tokens[3].size() <= 1 && m_creator.m_coding != PhraseTableCreator::None) { - std::cerr << "Error: It seems the following line contains no alignment information, " << std::endl; - std::cerr << "but you are using "; - std::cerr << (m_creator.m_coding == PhraseTableCreator::PREnc ? "PREnc" : "REnc"); - std::cerr << " encoding which makes use of alignment data. " << std::endl; - std::cerr << "Use -encoding None" << std::endl; - std::cerr << "Line " << i << ": " << lines[i] << std::endl; - abort(); + std::stringstream strme; + strme << "Error: It seems the following line contains no alignment information, " << std::endl; + strme << "but you are using "; + strme << (m_creator.m_coding == PhraseTableCreator::PREnc ? "PREnc" : "REnc"); + strme << " encoding which makes use of alignment data. " << std::endl; + strme << "Use -encoding None" << std::endl; + strme << "Line " << i << ": " << lines[i] << std::endl; + UTIL_THROW2(strme.str()); } std::vector scores = Tokenize(tokens[2]); if(scores.size() != m_creator.m_numScoreComponent) { - std::cerr << "Error: It seems the following line has a wrong number of scores (" + std::stringstream strme; + strme << "Error: It seems the following line has a wrong number of scores (" << scores.size() << " != " << m_creator.m_numScoreComponent << ") :" << std::endl; - std::cerr << "Line " << i << ": " << lines[i] << std::endl; - abort(); + strme << "Line " << i << ": " << lines[i] << std::endl; + UTIL_THROW2(strme.str()); } float sortScore = scores[m_creator.m_sortScoreIndex]; @@ -1136,19 +1140,21 @@ void EncodingTask::operator()() *it = Moses::Trim(*it); if(tokens.size() < 3) { - std::cerr << "Error: It seems the following line has a wrong format:" << std::endl; - std::cerr << "Line " << i << ": " << lines[i] << std::endl; - abort(); + std::stringstream strme; + strme << "Error: It seems the following line has a wrong format:" << std::endl; + strme << "Line " << i << ": " << lines[i] << std::endl; + UTIL_THROW2(strme.str()); } if(tokens[3].size() <= 1 && m_creator.m_coding != PhraseTableCreator::None) { - std::cerr << "Error: It seems the following line contains no alignment information, " << std::endl; - std::cerr << "but you are using "; - std::cerr << (m_creator.m_coding == PhraseTableCreator::PREnc ? "PREnc" : "REnc"); - std::cerr << " encoding which makes use of alignment data. " << std::endl; - std::cerr << "Use -encoding None" << std::endl; - std::cerr << "Line " << i << ": " << lines[i] << std::endl; - abort(); + std::stringstream strme; + strme << "Error: It seems the following line contains no alignment information, " << std::endl; + strme << "but you are using "; + strme << (m_creator.m_coding == PhraseTableCreator::PREnc ? "PREnc" : "REnc"); + strme << " encoding which makes use of alignment data. " << std::endl; + strme << "Use -encoding None" << std::endl; + strme << "Line " << i << ": " << lines[i] << std::endl; + UTIL_THROW2(strme.str()); } size_t ownRank = 0; diff --git a/moses/TranslationModel/PhraseDictionaryTree.cpp b/moses/TranslationModel/PhraseDictionaryTree.cpp index b31bf77f4..68dd5a59f 100644 --- a/moses/TranslationModel/PhraseDictionaryTree.cpp +++ b/moses/TranslationModel/PhraseDictionaryTree.cpp @@ -380,10 +380,8 @@ PhraseDictionaryTree::PhraseDictionaryTree() : imp(new PDTimp) { if(sizeof(OFF_T)!=8) { - TRACE_ERR("ERROR: size of type 'OFF_T' has to be 64 bit!\n" - "In gcc, use compiler settings '-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES'\n" - " -> abort \n\n"); - abort(); + UTIL_THROW2("ERROR: size of type 'OFF_T' has to be 64 bit!\n" + "In gcc, use compiler settings '-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES'\n"); } } @@ -506,10 +504,7 @@ int PhraseDictionaryTree::Create(std::istream& inFile,const std::string& out) } if (tokens.size() != numElement) { - std::stringstream strme; - strme << "Syntax error at line " << lnc << " : " << line; - UserMessage::Add(strme.str()); - abort(); + UTIL_THROW2("Syntax error at line " << lnc << " : " << line); } const std::string &sourcePhraseString =tokens[0] @@ -554,9 +549,8 @@ int PhraseDictionaryTree::Create(std::istream& inFile,const std::string& out) PSA::Data& d=psa->insert(f); if(d==InvalidOffT) d=fTell(ot); else { - TRACE_ERR("ERROR: source phrase already inserted (A)!\nline(" << lnc << "): '" - < sparseTokens = Tokenize(sparseFeatureString); if (sparseTokens.size() % 2 != 0) { - TRACE_ERR("ERROR: incorrectly formatted sparse feature string: " << - sparseFeatureString << std::endl); - abort(); + UTIL_THROW2("ERROR: incorrectly formatted sparse feature string: " << + sparseFeatureString); } for (size_t i = 0; i < sparseTokens.size(); i+=2) { fnames.push_back(imp->tv.add(sparseTokens[i])); @@ -608,9 +601,8 @@ int PhraseDictionaryTree::Create(std::istream& inFile,const std::string& out) PSA::Data& d=psa->insert(f); if(d==InvalidOffT) d=fTell(ot); else { - TRACE_ERR("ERROR: xsource phrase already inserted (B)!\nline(" << lnc << "): '" - < weight = staticData.GetWeights(this); if(m_numScoreComponents!=weight.size()) { std::stringstream strme; - strme << "ERROR: mismatch of number of scaling factors: "<Create(m_input, m_output, m_filePath, weight); diff --git a/moses/TranslationModel/RuleTable/LoaderStandard.cpp b/moses/TranslationModel/RuleTable/LoaderStandard.cpp index d60d44a21..9d2e3fa20 100644 --- a/moses/TranslationModel/RuleTable/LoaderStandard.cpp +++ b/moses/TranslationModel/RuleTable/LoaderStandard.cpp @@ -211,11 +211,8 @@ bool RuleTableLoaderStandard::Load(FormatType format } const size_t numScoreComponents = ruleTable.GetNumScoreComponents(); if (scoreVector.size() != numScoreComponents) { - stringstream strme; - strme << "Size of scoreVector != number (" << scoreVector.size() << "!=" - << numScoreComponents << ") of score components on line " << count; - UserMessage::Add(strme.str()); - abort(); + UTIL_THROW2("Size of scoreVector != number (" << scoreVector.size() << "!=" + << numScoreComponents << ") of score components on line " << count); } // parse source & find pt node diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp index 21b35b4df..7cb26ad88 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryFuzzyMatch.cpp @@ -200,10 +200,7 @@ void PhraseDictionaryFuzzyMatch::InitializeForInput(InputType const& inputSenten TokenizeMultiCharSeparator(tokens, *line , "|||" ); if (tokens.size() != 4 && tokens.size() != 5) { - stringstream strme; - strme << "Syntax error at " << ptFileName << ":" << count; - UserMessage::Add(strme.str()); - abort(); + UTIL_THROW2("Syntax error at " << ptFileName << ":" << count); } const string &sourcePhraseString = tokens[0] @@ -220,11 +217,8 @@ void PhraseDictionaryFuzzyMatch::InitializeForInput(InputType const& inputSenten Tokenize(scoreVector, scoreString); const size_t numScoreComponents = GetNumScoreComponents(); if (scoreVector.size() != numScoreComponents) { - stringstream strme; - strme << "Size of scoreVector != number (" << scoreVector.size() << "!=" - << numScoreComponents << ") of score components on line " << count; - UserMessage::Add(strme.str()); - abort(); + UTIL_THROW2("Size of scoreVector != number (" << scoreVector.size() << "!=" + << numScoreComponents << ") of score components on line " << count); } UTIL_THROW_IF2(scoreVector.size() != numScoreComponents,