[Iostreams] stream<file_sink> does not throw an exception and not set fail/bad bits when file is wrong

Hello! I'm trying to write some content to a new file using boost::stream<file_sink> class. Unfortunately errors/failures during opening the file are ignored by boost library. Here is a snippet: using namespace boost::iostreams; stream<file_sink> stream( "/wrong.txt" ); std::cout << stream.fail() << ' ' << stream.bad() << std::endl; stream.exceptions( std::ios::badbit | std::ios::failbit ); stream << "test" << std::endl; stream.close(); Program is started as not root user and have not access for file / wrong.txt. It should throw an exception, but instead of this: - console prints: 0 0 - none exception is thrown - file /wrong.txt is not created Similar piece of code using std::ofstream works as I expect: using namespace std; ofstream stream( "/wrong.txt" ); std::cout << stream.fail() << ' ' << stream.bad() << std::endl; stream.exceptions( std::ios::badbit | std::ios::failbit ); stream << "test" << std::endl; stream.close(); - console prints: 1 0 - exception is thrown I cannot believe that boost::iostreams has such obvious bug and just ignore failures! I have to do something wrong. But what? Regards, Mariusz Wojtysiak

On 2/8/2010 1:52 AM, Mariusz Wojtysiak wrote:
I cannot believe that boost::iostreams has such obvious bug and just ignore failures! I have to do something wrong. But what?
You don't mention what version of Boost you are using? While I dont know if will make a difference to your specific case, I know that a number of iostreams bug fixes made it into the latest Boost 1.42 release, including some related to throwing of exceptions. For details see: http://www.boost.org/doc/libs/1_42_0/libs/iostreams/doc/release_notes.html If your problem was tested against Boos 1.42, I would suggest, at minimum, entering a new ticket at: https://svn.boost.org/trac/boost/

On 10 Lut, 19:21, eg <ego...@gmail.com> wrote:
On 2/8/2010 1:52 AM, Mariusz Wojtysiak wrote: You don't mention what version of Boost you are using?
I used Boost 1.40. But also tested with 1.42 and problem stil exists.
If your problem was tested against Boos 1.42, I would suggest, at minimum, entering a new ticket at:https://svn.boost.org/trac/boost/
I created new ticket: https://svn.boost.org/trac/boost/ticket/3935 Mariusz
participants (2)
-
eg
-
Mariusz Wojtysiak