Skip to content

Commit

Permalink
File::GZ: Prevent throwing exception during destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Lestropie committed Apr 11, 2018
1 parent 89c0e44 commit 7544ade
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/file/gz.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <fcntl.h>
#include <zlib.h>

#include "debug.h"
#include "mrtrix.h"
#include "types.h"
#include "exception.h"
Expand All @@ -40,7 +41,12 @@ namespace MR
open (fname, mode);
}
~GZ () {
close();
try {
close();
} catch (...) {
FAIL ("error closing GZ file \"" + filename + "\": " + error());
App::exit_error_code = 1;
}
}

const std::string& name () const {
Expand All @@ -61,7 +67,7 @@ namespace MR
void close () {
if (gz) {
if (gzclose (gz))
throw Exception ("error closing file \"" + filename + "\": " + error());
throw Exception ("error closing GZ file \"" + filename + "\": " + error());
filename.clear();
gz = NULL;
}
Expand Down

0 comments on commit 7544ade

Please sign in to comment.