The C ++ standard ensures that std :: swap will not exclude.
No, it is not. See 20.2.2 or link . For two std::swap overloads, there are two noexcept specifications:
template<class T> void swap(T& a, T& b) noexcept(noexcept( std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value )) template<class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)))
When these conditions are not met, std::swap can throw, and you can catch it.
In the case of the class you presented, the predicates std::is_nothrow_move_constructible and std::is_nothrow_move_assignable are false, so there is no guarantee of no throw in the instance of std::swap<A> . It is perfectly legal to catch exceptions to this swap.
source share