473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1978

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jacques Labuschagne | last post by:
Hi all, Is it legal to kill an object and build a new one of the same type in its memory? class A{ int i; public: explicit A(int value): i(value){} };
3
by: Muki Rapp | last post by:
Hi! In the example below, once the media is full, the FileSteam.WriteByte throws an exception and the code is designed to handle it. However, when the GC is invoked, it calls the Finalize of...
4
by: SteveK | last post by:
**Newbie with managed C++** I'm trying to wrap an unmanaged C++ class in a managed C++ class library. When I instantiate the wrapper class it's ctor calls the ctor on the unmanaged class and at...
6
by: Klaus Ahrens | last post by:
hi all, acoording to the c++ standard "15.3. - -10- Referring to any non-static member or base class of an object in the handler for a function-try-block of a constructor or destructor for...
5
by: PasalicZaharije | last post by:
Hallo, few days ago I see ctor like this: Ctor() try : v1(0) { // some code } catch(...) { // some code }
5
by: Grahamo | last post by:
Hi, I have a basic question regarding some legacy code I'm working with; Basically the code looks something like this. I'd like to know if there are any reasons why a particular approach is...
7
by: Thomas | last post by:
I have a class foo whose ctor might throw an exception. When I create a foo object using "foo* myfoo = new foo;", and the ctor throws an exception, do I need to delete myfoo to free its memory?
4
by: ksukhonosenko | last post by:
This message was originally posted to comp.lang.c++.moderated ---------------------------------------------------------------------------------------------- Hi! I face a problem in my...
8
by: Grizlyk | last post by:
Good morning. Look here: http://groups.google.com/group/fido7.ru.cpp.chainik/browse_frm/thread/7341aba5238c0f79 and here:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.