Simple case
There is one unfortunate big highlight - perhaps due to a programmer error -
int main() { try { std::size_t bytesToAllocate; std::cin >> bytesToAllocate; std::unique_ptr<char> ptr { new char[bytesToAllocate - 1] };
Here, even if new fails, we definitely have more memory, because it has not been used before.
Realistic case
If, for some vague reason, the insertion of characters failed, the internal failbit turned on, i.e. setstate(std::ios_base::failbit) and, if exception set for failbit , an exception is thrown. Moreover, if an exception is badbit during insertion, badbit set badbit and if exception is set to badbit , the exception is returned.
However, AFAIK, it remains open and, therefore, is it not specified whether such an operation allocates memory or not, and how it is done. Your program may be killed due to out-of-memory protection and, thus, not being able to catch an exception if the entire process of distributing exceptions is possible at all in this state.
edmz source share