Skip to content

Instantly share code, notes, and snippets.

@j2doll
Created March 19, 2018 10:10
Show Gist options
  • Select an option

  • Save j2doll/f421f3e1bb2330532782e764d33ec293 to your computer and use it in GitHub Desktop.

Select an option

Save j2doll/f421f3e1bb2330532782e764d33ec293 to your computer and use it in GitHub Desktop.
StreamingException
// code from Dr.Dobbs (http://www.drdobbs.com/)
// StreamingException.h
//
#ifndef STREAMING_EXCEPTION
#define STREAMING_EXCEPTION
#include <iostream>
#include <sstream>
#include <memory>
#include <stdexcept>
class StreamingException : public std::runtime_error
{
public:
StreamingException() :
std::runtime_error(""),
ss_(std::auto_ptr<std::stringstream>
(new std::stringstream()))
{
}
~StreamingException() throw()
{
}
template <typename T>
StreamingException & operator << (const T & t)
{
(*ss_) << t;
return *this;
}
virtual const char * what() const throw()
{
s_ = ss_->str();
return s_.c_str();
}
private:
mutable std::auto_ptr<std::stringstream> ss_;
mutable std::string s_;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment