C++ Exception 库 - bad_typeid
描述
在空指针的 typeid 上引发此异常。
声明
以下是 std::bad_typeid 的声明。
class bad_typeid;
C++11
class bad_typeid;
参数
none
返回值
none
异常
No-throw guarantee − 没有成员抛出异常。
示例
In below example for std::bad_typeid.
#include <iostream>
#include <typeinfo>
struct S {
virtual void f();
};
int main() {
S* p = nullptr;
try {
std::cout << typeid(*p).name() << '\n';
} catch(const std::bad_typeid& e) {
std::cout << e.what() << '\n';
}
}
示例输出应该是这样的 −
std::bad_typeid

