If you throw an unhandled exception out of main
like this:
#include <stdexcept>
#include <iostream>
int main()
{
std::cout << "Hello World 1" << std::endl;
throw new std::invalid_argument("A");
return 0;
}
... then the process will terminate with the message "terminate called after throwing an instance of 'std::invalid_argument*'".
You will actually see this on the console:
Hello World 1
terminate called after throwing an instance of 'std::invalid_argument*'
If you print some more text without std::endl
and then throw the exception:
#include <stdexcept>
#include <iostream>
int main()
{
std::cout << "Hello World 1" << std::endl;
std::cout << "Hello World 2";
throw new std::invalid_argument("A");
return 0;
}
... then you won't see the second line on the console:
Hello World 1
terminate called after throwing an instance of 'std::invalid_argument*'
It seems that this error message overwrites the last line, e.g. by printing \r
before it.
How can this behavior be fixed?