D - [bug?] destructors called when exception leaves constructor
- Mike Swieton (10/10) Apr 04 2004 It seems that when an exception is thrown from a constructor, that objec...
- Ben Hinkle (7/17) Apr 04 2004 I believe C++ doesn't initialize the object before calling the
- Matthew (4/23) Apr 10 2004 I still philosophically feel that this is bad, if it is in fact true.
It seems that when an exception is thrown from a constructor, that object's destructor is still called. There are several problems with this: - Inconsistant with C++: Only fully constructed objects will have their destructors called in C++. - Dangerous: how does the destructor know what resources to release? I think this behavior is really asking for trouble. Mike Swieton __ Following the light of the sun, we left the Old World. - Inscribed on Columbus' caravels
Apr 04 2004
On Sun, 04 Apr 2004 21:38:45 -0400, Mike Swieton <mike swieton.net> wrote:It seems that when an exception is thrown from a constructor, that object's destructor is still called. There are several problems with this: - Inconsistant with C++: Only fully constructed objects will have their destructors called in C++.I believe C++ doesn't initialize the object before calling the constuctor. D initializes before calling the constructor so anything not "constructed" will at least be "initialized".- Dangerous: how does the destructor know what resources to release?It just checks if the resource is non-null (or whatever the initialization value is).I think this behavior is really asking for trouble. Mike Swieton __ Following the light of the sun, we left the Old World. - Inscribed on Columbus' caravels
Apr 04 2004
I still philosophically feel that this is bad, if it is in fact true. "Ben Hinkle" <bhinkle4 juno.com> wrote in message news:vpg170dekumvulfe94s40uoq5eenq2gd08 4ax.com...On Sun, 04 Apr 2004 21:38:45 -0400, Mike Swieton <mike swieton.net> wrote:object'sIt seems that when an exception is thrown from a constructor, thatdestructor is still called. There are several problems with this: - Inconsistant with C++: Only fully constructed objects will have their destructors called in C++.I believe C++ doesn't initialize the object before calling the constuctor. D initializes before calling the constructor so anything not "constructed" will at least be "initialized".- Dangerous: how does the destructor know what resources to release?It just checks if the resource is non-null (or whatever the initialization value is).I think this behavior is really asking for trouble. Mike Swieton __ Following the light of the sun, we left the Old World. - Inscribed on Columbus' caravels
Apr 10 2004