The following C++ program crashes on my Windows XP machine with a message “Abnormal program termination”
class Thing {};
int main()
{
for (;;) new Thing();
}
I would say it’s an out of memory problem, except I’m not sure Windows gets near the limit. Is it Windows killing it on purpose? If so, how does it decide?
You’re right it’s an out-of-memory problem that causes your program to end. But it’s not Windows that decides to end it with “Abnormal program termination”. It’s the C++ runtime (“msvcrt*.dll” on Windows) that raises the
std::bad_allocexception whennew Thingfails to allocate memory.You can verify that with a simple change:
This will end the program normally when the program is out of memory. If you don’t catch that exception, the unhandled exception will be handled by the C++ runtime, thus creating that famous “Abnormal program termination” message (or something similar).