On Mon, Aug 3, 2015 at 6:07 PM, Jonas Sicking <jo...@sicking.cc> wrote:
How would you make a factory function like the above fail? Returning > an nsresult will make it not much better than NS_NewFoo() pattern. > Returning null won't let you indicate a useful error code (though > maybe there's no such thing as useful error codes and we should just > report errors to the console). > > The only other alternative is to use the nsresult out argument, which > I agree is not easy on the eyes. Or return a Variant. static Variant<nsRefPtr<Foo>, ErrorType> Foo::Make(); ... auto /* lol */ fooOrError = Foo::Make(); if (fooOrError.is<ErrorType>()) { // Handle error... return; } auto foo = fooOrError.extract<nsRefPtr<Foo>>(); - Seth _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform