summaryrefslogtreecommitdiff
path: root/src/io/ozlibstream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/io/ozlibstream.cpp')
-rw-r--r--src/io/ozlibstream.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp
index cf0f505394..b936219787 100644
--- a/src/io/ozlibstream.cpp
+++ b/src/io/ozlibstream.cpp
@@ -101,9 +101,20 @@ void ozlibstream::close()
}
catch(...)
{
- setstate(badbit); //FIXME: This will throw the wrong type of exception
- //but there's no good way of setting the badbit
- //without causing an exception when exceptions is set
+ // Setting the stream state while exceptions are enabled may cause
+ // `setstate` to throw an `ios_base::failure` which would replace
+ // the original exception. Temporarily disable exceptions on this
+ // stream, set the `badbit`, then restore the exception mask.
+ std::ios_base::iostate old_ex = exceptions();
+ try {
+ exceptions(std::ios_base::goodbit);
+ setstate(std::ios_base::badbit);
+ }
+ catch(...) {
+ // If anything unexpected happens while setting state, swallow
+ // it — we don't want this to throw here.
+ }
+ exceptions(old_ex);
}
}