By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,156 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,156 IT Pros & Developers. It's quick & easy.

nothrow and exceptions

P: n/a
Is it possible for the nothrow form of the new operator to ever throw?
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Dave" <be***********@yahoo.com> wrote in message
news:vp***********@news.supernews.com...
Is it possible for the nothrow form of the new operator to ever throw?


Oh Lord, what on Earth is wrong with me...

Is it possible for *PLACEMENT* new to ever throw???

Somebody shoot me!!!
Jul 19 '05 #2

P: n/a

"Dave" <be***********@yahoo.com> wrote in message news:vp***********@news.supernews.com...
Is it possible for the nothrow form of the new operator to ever throw?


No...it has a throw() exception specification on it. If something inside it were to
throw, terminate() would be called.
Jul 19 '05 #3

P: n/a

"Dave" <be***********@yahoo.com> wrote in message news:vp************@news.supernews.com...
Is it possible for *PLACEMENT* new to ever throw???
Sure, the constructor for the object can throw. But the placment allocation
function can not throw. It's defined with a throw() exception specification.
Terminate() would be called even if the the allocation function was replaced
with something that would throw.
Somebody shoot me!!!


Bang.
Jul 19 '05 #4

P: n/a
In article <vp************@news.supernews.com>,
"Dave" <be***********@yahoo.com> wrote:
"Dave" <be***********@yahoo.com> wrote in message
news:vp***********@news.supernews.com...
Is it possible for the nothrow form of the new operator to ever throw?


Oh Lord, what on Earth is wrong with me...

Is it possible for *PLACEMENT* new to ever throw???

Somebody shoot me!!!


<chuckle> Actually your original question has interesting answers. Just
goes to show: there are no dumb questions! :-)

Yes, the nothrow form of the new operator can throw. Well, that's
probably a bit too inflamatory. A new-nothrow expression can throw.
Consider:

struct X
{
X() {throw "up";}
};

void foo()
{
X* xp = new (std::nothrow) X;
}

The new expression in foo() will throw, even though it is using the
nothrow expression. Same deal for placement new.

-Howard
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.