In More Effective C++, Scott Meyers says
C++ specifies that an object thrown as an exception is copied.
I suppose then, that if the copy constructor throws an exception in turn, std::terminate
is called, so this is a good reason for declaring all my exceptions' copy constructors noexcept
(and also, I guess, to not throw objects which allocate memory from the heap, like std::string
).
Yet I was surprised to see that the standard library implementation shipped with GCC 4.7.1 doesn’t define those copy constructor for std::bad_alloc
and std::exception
. Shouldn’t they define them noexcept
?