Is there a reference about C++ Standard Library Exceptions? I just want to know that which functions may throw an exception or not.
Actually, most of the standard library function don't throw exceptions themselves. They just pass on exception thrown by user code invoked by them. For example, if you
push_back() an element to a vector, this can throw (due to memory allocation errors and) if the object's copy constructor throws.
A few notable exceptions (no pun intended) where library functions throw are:
out_of_rangeif the index provided is invalid:
std::overflow_erroron integer overflow:
std::allocator<T>will pass on
newwhich it invokes.
std::ios_base::failureare thrown when a state bit is set.
std::bad_cast(technically not part of the standard library)
std::function::operator(...)if it has no value will throw
typeinfoof a null pointer may throw a
weak_ptrafter the pointee has been released will throw a
std::promise/std::futuremay throw a
std::stoldcan throw both
(I'm making this a CW answer, so if anyone can think of more such, please feel free to append them here.)
Also, for the 3rd edition of The C++ Programming Language, Bjarne Stroustrup has a downloadable appendix about exception safety, which might be relevant.