Created
March 19, 2018 10:10
-
-
Save j2doll/f421f3e1bb2330532782e764d33ec293 to your computer and use it in GitHub Desktop.
StreamingException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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