Pergunta de entrevista da empresa Microsoft

Phone interview question: What happens when the "new" operator in C++ fails?

Respostas da entrevista

Sigiloso

5 de mai. de 2009

I actually admitted that I didn't know the answer for sure, but I guessed that it would throw an exception. She said that it actually depends on the implementation; some will throw an exception, and some will return NULL, like "malloc". She sounded satisfied with my answer, though.

Sigiloso

1 de out. de 2011

Think usually it throws a bad_alloc exception. malloc does not throw an exception as far as I know.. just makes the pointer NULL