Re: HOWTO use a Factory
Goran wrote:
On Aug 22, 11:52 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Goran wrote:
[...]
Now I know it's bad to throw an exception in a constructor.
No, it's not bad. It's the only way to let the caller know that
construction cannot be completed.
Ok, it's not bad :) but how could i use a try/catch with such a
constructor?
try {
Example_t myExample("fooBar");
}
// myExample is lost...
Yes, here it's lost. Put all your code inside the 'try' clause.
catch(...) {
cout << "Exception" << endl;
}
But what else?
Depends.
[...]
The only "elegant" way that comes to mind is to return *a copy* of
some kind of "invalid" or "generic" object that can be inquired
about its own validity and discarded by the caller.
How looks like such an object :) ?
If you meant to ask, "what does such an object look like?", then
I have no idea since it's *your* object, *your* problem domain,
*your* model.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask