是否有可能在任何地方抛出异常的STL容器方法的列表? [英] Is there a list of STL container methods that may throw an exception anywhere?
问题描述
我知道STL会抛出一个内存分配错误或者如果包含的类型抛出它的构造函数/赋值运算符。
I know the STL will throw on a memory allocation error or if the contained type throws in its constructor / assignment operator.
否则,显然'方法可以抛出其他异常。每个人似乎都提到的例子是vector :: at(),但我找不到其他任何地方的列表。
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?
推荐答案
不是100%准确,而是 C ++ 03 半小时的努力基于通过GCC 4.3.4包括,忽略tr1和ext但包括iostream。至关重要的是,这些检查中的一些可能是由于这个实施喜欢更多的防御性编码,并且可能不是在标准中强制要求并可普遍使用....
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()
当太多位适合无符号长 -
std :: out_of_range
-运算符[]()
尝试超过结束
bitset
std::overflow_error
-.to_ulong()
when too many bits to fit in unsigned longstd::out_of_range
-operator[]()
attempt past end
-
std :: bad_alloc
std::bad_alloc
-
std :: bad_cast
无效dynamic_cast
尝试
std::bad_cast
on invaliddynamic_cast
attempt
- <$ c $
-
out_of_range
-append
/assign
/c> /
erase
/替换
/copy
/substr
-
length_error
:尝试超过max_size 或隐式调整大小(例如
assign
/insert
/+ =
li>
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.)
-
std :: bad_cast
如果语言环境不包含Facet
-
std :: runtime_error
在各种空指针/未定义方面的情况下
std::bad_cast
if locale doesn't contain a facet of typeFacet
std::runtime_error
in various null-pointer/undefined-facet situations
-
length_error
:attemptreserve()
或implicitly-grow>max_size code>
-
out_of_range
:在()
length_error
: attemptreserve()
or implicitly-grow >max_size()
out_of_range
:at()
-
std :: out_of_range
:at()
std::out_of_range
:at()
这篇关于是否有可能在任何地方抛出异常的STL容器方法的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-