定义于头文件
<stdexcept>
|
||
class logic_error;
|
||
定义作为异常抛出的对象的类型。它报告程序内部错误逻辑所导致的可避免错误,如违背逻辑前提条件或类不变量。
没有标准库组件直接抛出此异常,但异常类型
std::invalid_argument 、 std::domain_error 、 std::length_error 、 std::out_of_range 、 std::future_error 及 std::bad_optional_access 导出自 std::logic_error
。
目录 |
(构造函数)
|
构造异常对象 (公开成员函数) |
explicit logic_error( const std::string& what_arg );
|
(1) | |
explicit logic_error( const char* what_arg );
|
(2) | (C++11 起) |
以 what_arg
为解释性字符串构造异常对象,它能通过 what() 访问。
因为不允许 std::exception
的复制抛出异常,此信息典型地在内部作为分离分配的引用计数字符串存储。这也是构造函数不采用 std::string&&
参数的理由:无论如何它必须复制内容。
what_arg | - | 解释性字符串 |
可能抛出 std::bad_alloc
[虚]
|
析构该异常对象 ( std::exception 的虚公开成员函数)
|
[虚]
|
返回解释性字符串 ( std::exception 的虚公开成员函数)
|