M
mathieu
Dear c++ gurus,
I am trying to understand why the following piece of code is not
throwing any exception on my system. This is a simplified version just
for the demo (*). My implementation of sync always throw just for this
example. I am using Linux/g++ 4.4.5/debian.
Thanks for any clue,
(*)
#include <iostream>
#include <string>
int write_to_stdout(const char* text, size_t length)
{
std::string s ( text, text + length);
std::cout << s << std::endl;
return length;
}
class windowbuf : public std::streambuf {
public:
int sync ();
int overflow (int ch);
};
int windowbuf::sync ()
{
throw "Killing Program"; // where did it go ?
return windowbuf::traits_type::eof();
}
int windowbuf:
verflow (int ch)
{
std::streamsize n = pptr () - pbase ();
char buffer;
buffer = ch;
write_to_stdout( &buffer, 1 );
pbump (-n); // Reset pptr().
return 0;
}
int
main (int argc, char*argv[])
{
windowbuf wbuf;
std:
stream wstr(&wbuf);
wstr << "Hello world!" << std::flush;
return 0;
}
I am trying to understand why the following piece of code is not
throwing any exception on my system. This is a simplified version just
for the demo (*). My implementation of sync always throw just for this
example. I am using Linux/g++ 4.4.5/debian.
Thanks for any clue,
(*)
#include <iostream>
#include <string>
int write_to_stdout(const char* text, size_t length)
{
std::string s ( text, text + length);
std::cout << s << std::endl;
return length;
}
class windowbuf : public std::streambuf {
public:
int sync ();
int overflow (int ch);
};
int windowbuf::sync ()
{
throw "Killing Program"; // where did it go ?
return windowbuf::traits_type::eof();
}
int windowbuf:
{
std::streamsize n = pptr () - pbase ();
char buffer;
buffer = ch;
write_to_stdout( &buffer, 1 );
pbump (-n); // Reset pptr().
return 0;
}
int
main (int argc, char*argv[])
{
windowbuf wbuf;
std:
wstr << "Hello world!" << std::flush;
return 0;
}