Skip to content

Commit 7487324

Browse files
committed
Catch exceptions in destructor
1 parent 6aa3819 commit 7487324

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/util/Printer.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ namespace kanzi
3030
{
3131
public:
3232
Printer(std::ostream& os) { _os = &os; }
33-
~Printer() { _os->flush(); }
33+
34+
~Printer() {
35+
try {
36+
_os->flush();
37+
}
38+
catch (std::exception&) {
39+
// Ignore: best effort
40+
_os->setstate(std::ios::badbit);
41+
}
42+
}
3443

3544
void print(const char* msg, bool print) {
3645
if ((print == true) && (msg != nullptr)) {

0 commit comments

Comments
 (0)