私はこのようなものを書くことができる方法を見つけようとしています:
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_;
};