当我的 C++ 方法遇到奇怪的事情并且无法恢复时,我想抛出一个异常。可以抛出std::string
指针吗?
这是我期待做的事情:
void Foo::Bar() {
if(!QueryPerformanceTimer(&m_baz)) {
throw new std::string("it's the end of the world!");
}
}
void Foo::Caller() {
try {
this->Bar(); // should throw
}
catch(std::string *caught) { // not quite sure the syntax is OK here...
std::cout << "Got " << caught << std::endl;
}
}