mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-17 07:20:48 +03:00
Detect write errors in LVoc.
Write failures in LVoc::Write() were going unnoticed. If disk space runs out, the output file might get truncated without any indication of failure.
This commit is contained in:
parent
c6314d927d
commit
ae5ad8a49e
@ -58,7 +58,14 @@ public:
|
||||
|
||||
void Write(const std::string& fname) const {
|
||||
std::ofstream out(fname.c_str());
|
||||
// Little-known fact: ofstream tracks failures but does not, by default,
|
||||
// report them. You have to tell it to, or check for errors yourself.
|
||||
out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
Write(out);
|
||||
// Make sure the file is flushed, so that any errors are reported. If we
|
||||
// flush implicitly in the destructor, it won't be able to throw
|
||||
// exceptions.
|
||||
out.close();
|
||||
}
|
||||
void Write(std::ostream& out) const {
|
||||
for(int i=data.size()-1; i>=0; --i)
|
||||
|
Loading…
Reference in New Issue
Block a user