内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
我的C++方法遇到一些奇怪的东西,无法恢复时,我想抛出一个异常。
代码:
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; } }
std::exception
是C++标准库中的基本异常可能希望避免使用字符串作为异常类,因为它们本身可以在使用期间抛出异常。