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. 6 2000
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
* 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++.m oderated] 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?
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. Please ask in [comp.lang.c++.m oderated] right away, if you haven't already.
Why? are you not qualified to answer it?
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++.m oderated] 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?
puzzlecracker wrote: Please ask in [comp.lang.c++.m oderated] 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 :( This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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){}
};
|
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 FileSteam, who is trying
to flush and close the stream, but the disk is full, so the flush fails and
another exception is thrown from another
(GC) thread. An ugly solution would be to use GC.SuppressFinalize(fs).
Is there a better solution or good...
|
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 that point I get the exception:
"An unhandled exception of type 'System.StackOverflowException' occurred in
suabwrapper.dll"
I have been able to reproduce this with an unmanaged class that is VERY
simple:
|
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
that object results in undefined behavior."
it is not allowed to refer to l (delete l;) in the following code
|
by: PasalicZaharije |
last post by:
Hallo,
few days ago I see ctor like this:
Ctor() try : v1(0) {
// some code
}
catch(...) {
// some code
}
| |
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 taken.
Given a type X we have a class something like this;
class foo
|
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?
|
by: ksukhonosenko |
last post by:
This message was originally posted to comp.lang.c++.moderated
----------------------------------------------------------------------------------------------
Hi!
I face a problem in my production code. I could deduce this problem to
program shown below. It seems, that try-block in constructor doesnt
work as it should (compared to case where no try block exists at all).
I tested this small program on my MSVC .NET Pro 2003 (and separately...
|
by: Grizlyk |
last post by:
Good morning.
Look here:
http://groups.google.com/group/fido7.ru.cpp.chainik/browse_frm/thread/7341aba5238c0f79
and here:
http://groups.google.com/group/fido7.ru.cpp.chainik/browse_frm/thread/cb014f4ba9df614a
Can anybody answer?
Who can't read in russian:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |