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: What is function pageLoad()
    ... I like #1 better than the way I did it in the constructor. ... and c# I need to register Page_load in the constructor. ... to load client side variables when you are using AJAX. ... I copied into another .aspx file and it does NOT execute. ...
    (microsoft.public.dotnet.framework.aspnet)
  • 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)