Google's Go & Exceptions
Walter Bright
newshound1 at digitalmars.com
Tue Jan 26 15:14:10 PST 2010
dsimcha wrote:
> I've never understood the recommendation not to put complex logic in the
> constructor.
Complex logic is fine, just logic that cannot fail.
> If you need complex logic to establish the class's invariant, or
> need to initialize complicated immutable data structures, where else is that logic
> supposed to go?
For example, allocating resources that might fail, can be done with a
separate initialization function:
auto c = new Class;
c.create();
More information about the Digitalmars-d
mailing list