new and memory allocation error
Another quick question!
When standard new cannot allocate the requested storage in C++ which of the following does it do? (standard behaviour). (can be more than one answer)
1 - throws a bad_alloc exception
2 - throws an insufficient_memory exception
3 - returns null
4 - returns silently with no effect on the expression
5 - logs an error message to the mem_err.log file
I would have said definitly 1, any other thoughts or interesting info about the others?
Is there any way I can force this error so I can try it out?
Re: new and memory allocation error
If the nothrow version of new is used, then 3 would be correct. However, the question probably isn't asking about that.
Re: new and memory allocation error
thanks for the reply, so would you think it is just 1?
Re: new and memory allocation error
Well, there would be no point in throwing two exceptions for the same thing, and if an exception is thrown then it doesn't make sense to talk about a return value. Plus I can't imagine standard C++ doing any logging you didn't ask it to do.
I suppose #4 might make sense depending on what they mean by "returns silently". Jumping directly to the catch block (if any) will certainly not have any effect on the expression...