I’m a new C++ programmer, so I never wrote C++ code for anything older than C++11. I was reading Scott Meyers "Effective C++, 2nd Edition" (I know it is old, but I think it still has some valid points).
In the book, according to "Item 7", new can throw exceptions which should be handled.
Can new still throw exceptions?
Should I be prepared about exceptions that could be thrown by a smart pointer or new?
>Solution :
Yes, on allocation new can throw a bad_alloc exception.
That is, unless you pass const std::nothrow_t& as the second parameter, where you’ll be guaranteed a return value of nullptr
See details here