std::out_of_range_C++中文网
| 定义于头文件 |
||
| class out_of_range; |
||
定义作为异常抛出的对象类型。它报告访问试图受定义范围外的元素所带来的错误。
它可能为 std::bitset 与 std::basic_string 的成员函数、 std::stoi 与 std::stod 函数族及有边界检查的成员访问函数(例如 std::vector::at 与 std::map::at )所抛出。
继承图
成员函数
| (构造函数) |
构造异常对象 (公开成员函数) |
std::out_of_range::out_of_range
| explicit out_of_range( const std::string& what_arg ); |
(1) | |
| explicit out_of_range( const char* what_arg ); |
(2) | (C++11 起) |
以 what_arg 为解释字符串构造异常对象,能通过 what() 访问它。
因为不容许复制 std::out_of_range 抛出异常,通常将此消息在内部存储为分离分配的引用计数字符串。这也是构造函数不接收 std::string&& 参数的理由:无论如何它必须复制内容。
参数
| what_arg | - | 解释字符串 |
异常
可能抛出 std::bad_alloc
继承自 std::exception
成员函数
| [虚] |
析构该异常对象 ( std::exception 的虚公开成员函数) |
| [虚] |
返回解释性字符串 ( std::exception 的虚公开成员函数) |
注意
标准错误条件 std::errc::result_out_of_range 典型地指示结果而非输入在范围外的条件,而且与 std::range_error 及 ERANGE 关联更紧密。
参阅
| 访问指定字符,有边界检查 ( std::basic_string<CharT,Traits,Allocator> 的公开成员函数) |