On Mon, 10 Nov 2008 12:39:26 -0800, Peter Morris
<mr*********@spamgmail.comwrote:
The only way for a constructor to fail is to throw an exception isn't it?
It depends on how you define "fail".
That certainly is the canonical way, and in the sense that it's the only
way to prevent an object reference from being returned to the code site
instantiating the object with "new", you're right. But exceptions are far
from the only way to report a failure, and a class _could_ decide to
always allow the object to be instantiated and require the caller to check
some other state, such as the value in an "out" argument, a property,
calling some validation method, or even checking some global state (the
first two were even mentioned as possible methods in this thread already).
All of those approachs, and others not even mentioned, could be considered
a legitimate way to report "failure".
Pete