如果我这样做:
//... in .h header:
class MyCustomException : public std::exception{
private:
string message;
public:
MyCustomException (string msg); //in .cpp implements "message = msg"
~MyCustomException() throw(){ }
string what(); //implemented to return message.
}
Run Code Online (Sandbox Code Playgroud)
//... other code ... in cpp:
if (<blah blah blah>){
throw MyCustomException("I want to see THIS message when I fail ... but I don't...");
}
//... more code, in cpp:
//try{<blah...>}
catch(const:: std::exception& e){
cout << e.what() << endl << flush; //just prints "std::exception" ... same if …Run Code Online (Sandbox Code Playgroud)