Boost C++ Libraries: Ticket #4807: Sink devices "leacks" exception out of the stream https://svn.boost.org/trac10/ticket/4807 <p> I implement the sink device that sometimes may fail on writes. When Sink is implemented it should throw an exception on fault to notify the stream on error. </p> <p> However it is not always works this way. I've got the exception to "leak" to the main program when I combine in the filter gzip_comressor() filter that writes to output device that its Sink is full. When I call reset on the filter the exception in leaking to the program instead of being caught. </p> <p> On the other hand, if I don't throw but rather return 0, I get into infinite loop in the boost::iostreams::non_blocking_adapter::write when I call filter.reset(). </p> <p> In following example the exception is caught when filter.reset() is called, when it shouldn't. </p> <pre class="wiki"> #include &lt;boost/iostreams/stream.hpp&gt; #include &lt;boost/iostreams/filtering_stream.hpp&gt; #include &lt;boost/iostreams/filter/gzip.hpp&gt; #include &lt;boost/iostreams/tee.hpp&gt; #include &lt;iostream&gt; class my_small_device : public boost::iostreams::sink { int count; public: my_small_device() : count(1000) {} std::streamsize write(char const *d,std::streamsize n) { if(count &lt; n) throw std::runtime_error("Device is full"); count-=n; return n; } }; int main() { try { using namespace boost::iostreams; boost::iostreams::stream&lt;my_small_device&gt; output(my_small_device(),10); { boost::iostreams::filtering_ostream filter; filter.push(gzip_compressor()); filter.push(output); for(int i=0;i&lt;10000000;i++) { if(!(filter &lt;&lt; i &lt;&lt; '\n')) { std::cerr &lt;&lt; "Fail!" &lt;&lt; std::endl; break; } } std::cout &lt;&lt; "Closing filter" &lt;&lt; std::endl; filter.reset(); } std::cout &lt;&lt; "ok" &lt;&lt; std::endl; return 0; }catch(std::exception const &amp;e) { std::cerr &lt;&lt; "Catched " &lt;&lt; e.what() &lt;&lt; std::endl; return 1; } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4807 Trac 1.4.3