On 2009-11-30 10:30:11 -0500, Andrei Alexandrescu <[email protected]> said:

class MyException : Exception {
     private int sysCode;
     invariant() { assert(sysCode < 100); }
}

If default initialization of the field puts it in a state that respects the invariant, there isn't a problem.

I think this simply shows that if super's constructor is inherited, once the object is constructed invariant() should be called (and not super's invariant, the one of the object actually constructed). If you do that you'll catch any field not respecting the invariant right after construction.

--
Michel Fortin
[email protected]
http://michelf.com/

Reply via email to