Thread overview | |||||
---|---|---|---|---|---|
|
April 05, 2004 [bug?] destructors called when exception leaves constructor | ||||
---|---|---|---|---|
| ||||
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 |
April 05, 2004 Re: [bug?] destructors called when exception leaves constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Swieton | 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 |
April 10, 2004 Re: [bug?] destructors called when exception leaves constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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: > > >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 > |
Copyright © 1999-2021 by the D Language Foundation