当我的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;
}
}