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?
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 invalid dynamic_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 exceed max_size()
during reserve
or implicit resize (e.g. assign
/insert
/+=
etc.)locale
std::bad_cast
if locale doesn't contain a facet of type Facet
std::runtime_error
in various null-pointer/undefined-facet situationsdeque
/vector
length_error
: attempt reserve()
or implicitly-grow > max_size()
out_of_range
: at()
map
std::out_of_range
: at()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With