我试图找出如何能够写出这样的东西:
try{
throw MyCustomException;
}
catch(const MyCustomException &e){
cout<< e;
}
但是如何定义overloaded operator <<
这个目的呢?
自定义异常类:
class MyCustomException{
public:
MyCustomException(const int& x) {
stringstream ss;
ss << x;
msg_ = "Invalid index [" + ss.str() + "]";
}
string getMessage() const {
return (msg_);
}
private:
string msg_;
};