是否有可能在任何地方抛出异常的 STL 容器方法列表?
我知道 STL 会抛出内存分配错误,或者如果包含的类型在其构造函数/赋值运算符中抛出异常。
否则,显然“一些”STL 方法可能会引发其他异常。每个人似乎都提到的示例是 vector::at(),但我在任何地方都找不到其他示例的列表。
有谁知道这样的清单吗?
I know the STL will throw on a memory allocation error or if the contained type throws in its constructor / assignment operator.
Otherwise, apparently 'a few' STL methods can throw other exceptions. The example everyone seems to mention is vector::at(), but I can't find a list of the others anywhere.
Does anyone know of such a list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会是 100% 准确,并且适用于 C++03,但是基于 GCC 4.3.4 的 grep 半小时的努力包括忽略 tr1 和 ext 但包括 iostream。至关重要的是,其中一些检查可能是由于该实现更喜欢防御性编码,并且可能没有在标准中强制执行并且可以普遍使用......
bitset
std::overflow_error
-.to_ulong()
当太多位无法容纳 unsigned longstd::out_of_range
-operator[]()
尝试超过末尾new
std::bad_alloc
类型信息
std::bad_cast
尝试dynamic_cast
无效ios
std::ios_base::failure
使用异常掩码进行错误报告时string
out_of_range
-at
/追加
/分配
/插入
/删除
/替换
/复制
/substr
length_error
:在reserve
或隐式调整大小期间尝试超过max_size()
(例如分配
/插入
/+=
等)语言环境
std::bad_cast
如果语言环境不包含Facet
类型的构面std::runtime_error
在各种空指针/未定义方面的情况下deque
/vector
length_error
:尝试reserve()
或隐式增长>max_size()
out_of_range
:at()
地图
std::out_of_range
:at()
Won't be 100% accurate, and is for C++03, but a half-hour effort based on grepping through GCC 4.3.4 includes, ignoring tr1 and ext but including iostream. Crucially, some of these checks might be due to this implementation prefering more defensive coding, and might not be mandated in the Standard and available universally....
bitset
std::overflow_error
-.to_ulong()
when too many bits to fit in unsigned longstd::out_of_range
-operator[]()
attempt past endnew
std::bad_alloc
typeinfo
std::bad_cast
on invaliddynamic_cast
attemptios
std::ios_base::failure
when using exception masks for error reportingstring
out_of_range
-at
/append
/assign
/insert
/erase
/replace
/copy
/substr
length_error
: attempt to exceedmax_size()
duringreserve
or implicit resize (e.g.assign
/insert
/+=
etc.)locale
std::bad_cast
if locale doesn't contain a facet of typeFacet
std::runtime_error
in various null-pointer/undefined-facet situationsdeque
/vector
length_error
: attemptreserve()
or implicitly-grow >max_size()
out_of_range
:at()
map
std::out_of_range
:at()
嗯,我有一本巨大的书,名为C++ 标准,其中包含标准库中所有函数以及它们可以/不能做什么的完整描述。
Well, I have this big, gigantic book titled, The C++ Standard, that contains a complete description of all functions in the standard library and what they can/cannot do.