The Wayback Machine - https://web.archive.org/web/20180511105233/http://zh.cppreference.com:80/w/cpp/error/overflow_error

std::overflow_error

来自cppreference.com
< cpp‎ | error
 
 
 
 
 
定义于头文件 <stdexcept>
class overflow_error;

定义作为异常抛出的对象类型。它能用于报告算术上溢错误(即计算结果对目标类型过大的情形)。

仅有的抛此异常的标准库组件是 std::bitset::to_ulongstd::bitset::to_ullong

标准库组件的数学函数不抛此异常(数学函数按指定于 math_errhandling 的方式报告上溢错误)。然而第三方库使用它。例如,若启用 boost::math::policies::throw_on_error (默认设置),则 boost.math 抛出 std::overflow_error

cpp/error/exceptioncpp/error/runtime errorstd-overflow error-inheritance.svg
关于这幅图像

继承图

目录

[编辑] 成员函数

(构造函数)
构造异常对象
(公开成员函数) [编辑]

std::overflow_error::overflow_error

explicit overflow_error( const std::string& what_arg );
(1)
explicit overflow_error( const char* what_arg );
(2) (C++11 起)

what_arg 为解释字符串构造异常对象,能通过 what() 访问它。

因为不容许从 std::exception 派生的标准库类的复制抛出异常,此信息典型地在内部作为分离分配的引用计数字符串存储。这也是构造函数不采用 std::string&& 参数的理由:无论如何它必须复制内容。

参数

what_arg - 解释字符串

异常

可能抛出 std::bad_alloc

继承自 std::exception

成员函数

析构该异常对象
(std::exception 的虚公开成员函数) [编辑]
[虚]
返回解释性字符串
(std::exception 的虚公开成员函数) [编辑]