C++ Exception 库 - bad_exception
描述
这是意外处理程序引发的异常。
声明
以下是 std::bad_exception 的声明。
class bad_exception;
C++11
class bad_exception;
参数
none
返回值
none
异常
No-throw guarantee − 没有成员抛出异常。
示例
在下面的 std::bad_exception 示例中。
#include <iostream>
#include <exception>
#include <stdexcept>
void my_unexp() { throw; }
void test() throw(std::bad_exception) {
throw std::runtime_error("test error");
}
int main() {
std::set_unexpected(my_unexp);
try {
test();
} catch(const std::bad_exception& e) {
std::cerr << "Caught " << e.what() << '\n';
}
}
示例输出应该是这样的 −
Caught std::bad_exception

