Re: exception inside constructors and finalize



Ross Bamford wrote:

I guess from the day-to-day programmer perspective, it
doesn't really matter unless you're keeping extra
references like above, the effect is the same (?), but
then it's one of those situations where you innocently do
keep a reference one time and end up chasing the same bug
for days ;)

I think the main conclusion for everyday programming is that, if you must register an object with its class or another object from the constructor, that should be the very last thing the constructor does, after anything else that might possibly throw an exception.

Of course, if the object's class is non-final, there is
still the problem of subclass constructor bodies that run
after the end of the superclass constructor.

A better solution is to treat registration of objects as a
separate action, and limit the constructor to building the
object's own state.

Patricia

.



Relevant Pages

  • Re: Implicit overloads, non static
    ... you've disputed whether it's a matter of implementation rather ... that's clearer - but I wasn't disputing that. ... > I find a lot of things hard in Java. ... I'm not sure I'd call that a copy constructor myself, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inherited Methods and such
    ... Initialize converts the object X to T'Class. ... a hook on the constructor of T'Class which is officially constructed, ... re-dispatch is inherently inconsistent. ... you have to way to register T'Class reference/pointer from T's ...
    (comp.lang.ada)
  • Re: Implicit overloads, non static
    ... you've disputed whether it's a matter of implementation rather ... > than principle. ... that's clearer - but I wasn't disputing that. ... I'm not sure I'd call that a copy constructor myself, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Thread problem (constructor+assignement in one step?)
    ... >> use smart pointers and a mark and a simple sweep gc. ... The constructor of smartptr has also been ... >> adjusted to register new instances of smart pointers with the garbage ... > and by using GC safe-points. ...
    (comp.lang.cpp)
  • Re: Inherited Methods and such
    ... Forget dynamic dispatch where you are in the constructor. ... I'm arguing against using this concept in the context of constructor. ... that I can register. ... Whether references need to have types at all is a matter of taste. ...
    (comp.lang.ada)