#include "exceptionstream.h" #include "debug.h" #include #include #include #ifdef ExceptionStream_NO_SSTREAM const char* exception_stream::what() const throw() { this->buffer = ""; char c; this->stream.flush(); this->stream.close(); //std::cerr << "tmp filename is " << this->m_filename << "\n"; std::ifstream in( this->filename.c_str()); if ( !in) { std::cerr << "couldn't open tmp file for reading"; } else { while ( in.get(c)) { this->buffer += c; } } in.close(); this->stream.open( this->filename.c_str()); //std::cerr << "what() returning: " << this->buffer << "\n"; return this->buffer.c_str(); } exception_stream& exception_stream::operator = ( const exception_stream& rhs) { this->stream.close(); remove( this->filename.c_str()); this->stream.open( this->filename.c_str()); this->stream << rhs.what(); return *this; } exception_stream::exception_stream( const exception_stream& rhs) : std::exception(), filename( tmpnam( NULL)), stream( filename.c_str()) { debug << "exception_stream::exception_stream:\n"; debug_output_backtraces(); this->stream << rhs.what(); } exception_stream::exception_stream() : std::exception(), filename( tmpnam( NULL)), stream( filename.c_str()), buffer() { } exception_stream::~exception_stream() throw() { this->stream.close(); remove( this->filename.c_str()); //std::cerr << "tmpfilename is " << this->m_filename << "\n"; } #else exception_stream::exception_stream() : std::exception(), stream(), buffer_for_what() { debug << "exception_stream::exception_stream:\n"; debug_output_backtraces(); } exception_stream& exception_stream::operator = ( const exception_stream& rhs) { this->stream << rhs.what(); return *this; } exception_stream::exception_stream( const exception_stream& rhs) : std::exception(), stream(), buffer_for_what() { this->stream << rhs.what(); } const char* exception_stream::what() const throw() { this->buffer_for_what += this->stream.str().c_str(); this->stream.clear(); return this->buffer_for_what.c_str(); } exception_stream::~exception_stream() throw() { } #endif