|
-
September 1st, 2009, 11:59 AM
#1
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?
-
September 1st, 2009, 01:02 PM
#2
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.
-
September 1st, 2009, 01:07 PM
#3
Re: new and memory allocation error
thanks for the reply, so would you think it is just 1?
-
September 1st, 2009, 01:10 PM
#4
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|