470,870 Members | 1,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

ctor throws an exception case

When ctor throws an exception, dtor is not called for that object
(correct me if I am wrong) - then how would already allocated memebers
de-allocated?

Thanks.

May 10 '06 #1
6 1847

puzzlecracker skrev:
When ctor throws an exception, dtor is not called for that object
(correct me if I am wrong) - then how would already allocated memebers
de-allocated?

Thanks.


Is that not in the faq? Because every object constructed will be
destructed when unwinding:

class A
{
....
}
class B
{
....
}
class D: B
{
A a;
D() {throw;}
}

Above B::~B and A::~A will both be called (assuming A and B's
constructor does not throw).

/Peter

May 10 '06 #2
* puzzlecracker:
When ctor throws an exception, dtor is not called for that object
(correct me if I am wrong) - then how would already allocated memebers
de-allocated?


Please ask in [comp.lang.c++.moderated] right away, if you haven't already.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 10 '06 #3
On Wed, 10 May 2006 15:17:57 -0700, puzzlecracker wrote:
When ctor throws an exception, dtor is not called for that object
(correct me if I am wrong) - then how would already allocated memebers
de-allocated?


Correct. If an exception propogates out of a ctor, the dtor for that
object will not be invoked as that object had not completed construction.
Any member variables of that object that had ben completely constructed
will be destroyed in the reverse order that they were constructed in (as
normal).

Note that the destructor of a pointer-to-object doesn't do anything...
that's what std::auto_ptr (and other relatives of it) are for.
May 10 '06 #4
Please ask in [comp.lang.c++.moderated] right away, if you haven't already.


Why? are you not qualified to answer it?

May 10 '06 #5

Alf P. Steinbach skrev:
* puzzlecracker:
When ctor throws an exception, dtor is not called for that object
(correct me if I am wrong) - then how would already allocated memebers
de-allocated?
Please ask in [comp.lang.c++.moderated] right away, if you haven't already.

Ouch! So he already asked there? I had some kind of a dejŠ vý
experience, but a quick check did not show anything.

/Peter --
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


May 10 '06 #6

puzzlecracker wrote:
Please ask in [comp.lang.c++.moderated] right away, if you haven't already.


Why? are you not qualified to answer it?


he clearly called you a cross-poster. I am sure you got that!

dissimulation is futile :(

May 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jacques Labuschagne | last post: by
6 posts views Thread by Klaus Ahrens | last post: by
5 posts views Thread by PasalicZaharije | last post: by
5 posts views Thread by Grahamo | last post: by
7 posts views Thread by Thomas | last post: by
4 posts views Thread by ksukhonosenko | last post: by
8 posts views Thread by Grizlyk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.