How to throw meaningful data in exceptions ?
Posted
by
ZeroCool
on Stack Overflow
See other posts from Stack Overflow
or by ZeroCool
Published on 2011-01-16T11:51:19Z
Indexed on
2011/01/16
11:53 UTC
Read the original article
Hit count: 183
I would like to throw exceptions with meaningful explanation ! I thought of using variable arguments worked fine but lately I figured out it's impossible to extend the class in order to implement other exception types. So I figured out using an std::ostreamstring as a an internal buffer to deal with formatting ... but doesn't compile! I guess it has something to deal with copy constructors. Anyhow here is my piece of code:
class Exception: public std::exception {
public:
Exception(const char *fmt, ...);
Exception(const char *fname,
const char *funcname, int line, const char *fmt, ...);
//std::ostringstream &Get() { return os_ ; }
~Exception() throw();
virtual const char *what() const throw();
protected:
char err_msg_[ERRBUFSIZ];
//std::ostringstream os_;
};
The variable argumens constructor can't be inherited from! this is why I thought of std::ostringstream! Any advice on how to implement such approach ?
© Stack Overflow or respective owner