std::bad_typeid
来自 cppreference.cn
定义于头文件 <typeinfo> |
||
class bad_typeid : public std::exception; |
||
当 typeid 运算符应用于多态类型的解引用空指针值时,将抛出此类型的异常。
继承关系图
内容 |
[编辑] 成员函数
(构造函数) |
构造一个新的 bad_typeid 对象(公有成员函数) |
operator= |
替换 bad_typeid 对象(公有成员函数) |
what |
返回解释性字符串 (公有成员函数) |
std::bad_typeid::bad_typeid
(1) | ||
bad_typeid() throw(); |
(直到 C++11) | |
bad_typeid() noexcept; |
(自 C++11 起) | |
(2) | ||
bad_typeid( const bad_typeid& other ) throw(); |
(直到 C++11) | |
bad_typeid( const bad_typeid& other ) noexcept; |
(自 C++11 起) | |
构造一个新的 bad_typeid
对象,该对象带有一个实现定义的空终止字节字符串,可以通过 what() 访问。
1) 默认构造函数。
2) 复制构造函数。 如果 *this 和 other 都具有动态类型
std::bad_typeid
,则 std::strcmp(what(), other.what()) == 0。(自 C++11 起)参数
other | - | 要复制的另一个异常对象 |
std::bad_typeid::operator=
bad_typeid& operator=( const bad_typeid& other ) throw(); |
(直到 C++11) | |
bad_typeid& operator=( const bad_typeid& other ) noexcept; |
(自 C++11 起) | |
将内容赋值为 other 的内容。 如果 *this 和 other 都具有动态类型 std::bad_typeid
,则在赋值后 std::strcmp(what(), other.what()) == 0。(自 C++11 起)
参数
other | - | 要赋值的另一个异常对象 |
返回值
*this
std::bad_typeid::what
virtual const char* what() const throw(); |
(直到 C++11) | |
virtual const char* what() const noexcept; |
(自 C++11 起) (constexpr 自 C++26 起) |
|
返回解释性字符串。
返回值
指向实现定义的空终止字符串的指针,其中包含解释性信息。该字符串适合转换为 std::wstring 并显示。指针保证至少在从中获取它的异常对象被销毁之前,或者在该异常对象上调用非 const 成员函数(例如,复制赋值运算符)之前有效。
返回的字符串在使用常量求值期间的普通字面量编码进行编码。 |
(自 C++26 起) |
注释
允许但不是必须重写 what()
的实现。
继承自 std::exception
成员函数
[虚拟] |
销毁异常对象 ( std::exception 的虚拟公有成员函数) |
[虚拟] |
返回解释性字符串 ( std::exception 的虚拟公有成员函数) |
[编辑] 注释
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_constexpr_exceptions |
202411L |
(C++26) | constexpr 用于异常类型 |
[编辑] 示例
运行此代码
可能的输出
Attempted a typeid of NULL pointer!