April 20, 2004 Return Codes from Constructor | ||||
---|---|---|---|---|
| ||||
I am unfamiliar with D but have read most of the user manual. I am disappointed to find that constructors cannot return an error code since I assume that they also cannot throw an exception (although I can't find this stated anywhere). In a telecommunications system, where the system cannot stop, it is essential for a constructor to be able to return a code to say "I didn't initialise properly, don't use me". This may result from the object being unable to get enough memory or other resources. Without a return code or exception (as in C++) it is necessary to define a public method bool createdOK(); which the creator must remember to call to see whether the object is in a zombiue state, having not really been created. This leads to all sorts of errors when people forget to call createdOK(); Chris Hobbs |
April 20, 2004 Re: Return Codes from Constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Hobbs | "Chris Hobbs" <Chris_member@pathlink.com> wrote in message news:c642il$okl$1@digitaldaemon.com... > I am unfamiliar with D but have read most of the user manual. > > I am disappointed to find that constructors cannot return an error code since I > assume that they also cannot throw an exception (although I can't find this > stated anywhere). They can. > In a telecommunications system, where the system cannot stop, it is essential > for a constructor to be able to return a code to say "I didn't initialise properly, don't use me". This may result from the object being unable to get > enough memory or other resources. Without a return code or exception (as in C++) > it is necessary to define a public method > > bool createdOK(); > > which the creator must remember to call to see whether the object is in a zombiue state, having not really been created. This leads to all sorts of errors > when people forget to call createdOK(); > > Chris Hobbs |
Copyright © 1999-2021 by the D Language Foundation