There are several special functions which usually guarantee not to throw excpetions, e.g.:
- Destructors
swap
method
Consider the following swap
implementation, as stated in this answer:
friend void swap(dumb_array& first, dumb_array& second)
{
using std::swap;
swap(first.mSize, second.mSize);
swap(first.mArray, second.mArray); // What if stack overlow occurs here?
}
It uses two swap
functions - for integer and for pointer. What if the second function will cause stack overflow? Objects will become corrupted. I guess it is not an std::exception
, it is some kind of system exception, like Win32-exception
. But now we cannot guarantee no-throwing, since we're calling a function.
But all authoritative sources just use swap
like it's ok, no exceptions will ever be thrown here. Why?