diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2014-01-13 22:32:22 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2014-01-13 22:32:22 +0400 |
commit | fccf2ea43a7ff0846dbb1bf77df32b7d85186e63 (patch) | |
tree | 97f95116d5e0ad2263fe3b03b93d1c0295554c6c /moses/File.h | |
parent | b5558c36b85177bf282cb88edd3b899872b7a9b9 (diff) |
get rid of all aborts from decoder
Diffstat (limited to 'moses/File.h')
-rw-r--r-- | moses/File.h | 32 |
1 files changed, 13 insertions, 19 deletions
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 <cstdio> #include <iostream> +#include <sstream> #include <vector> #include "util/exception.hh" #include "UserMessage.h" @@ -37,8 +38,7 @@ static const OFF_T InvalidOffT=-1; template<typename T> 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<typename T> inline size_t fWrite(FILE* f,const T& t) template<typename T> 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<typename T> 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<typename T> 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<typename C> 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<typename C> 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! "<<r<<" "<<s<<"\n"); - abort(); + UTIL_THROW2("ERROR: freadVec! "<<r<<" "<<s); } } @@ -100,8 +95,7 @@ inline size_t fWriteString(FILE* f,const char* e, UINT32 s) { size_t rv=fWrite(f,s); if(fwrite(e,sizeof(char),s,f)!=s) { - TRACE_ERR("ERROR:: fwrite!\n"); - abort(); + UTIL_THROW2("ERROR:: fwrite!"); } return rv+sizeof(char)*s; } @@ -112,8 +106,7 @@ inline void fReadString(FILE* f,std::string& e) fRead(f,s); char* a=new char[s+1]; if(fread(a,sizeof(char),s,f)!=s) { - TRACE_ERR("ERROR: fread!\n"); - abort(); + UTIL_THROW2("ERROR: fread!"); } a[s]='\0'; e.assign(a); @@ -149,9 +142,10 @@ inline OFF_T fTell(FILE* f) inline void fSeek(FILE* f,OFF_T o) { if(FSEEKO(f,o,SEEK_SET)<0) { - TRACE_ERR("ERROR: could not fseeko position "<<o<<"\n"); - if(o==InvalidOffT) TRACE_ERR("You tried to seek for 'InvalidOffT'!\n"); - abort(); + std::stringstream strme; + strme << "ERROR: could not fseeko position " << o <<"\n"; + if(o==InvalidOffT) strme << "You tried to seek for 'InvalidOffT'!\n"; + UTIL_THROW2(strme.str()); } } |