I´ve lately been thinking about the things i´m returning from methods and I noticed that there are 4 different things i return when the method fails.
What bothers me about it, is that my code is not very consitent in this regard, so i wanted to ask about your "best practices".
So lets imagine a method that takes Foo and returns a list of Bar:
public IList<Bar> Method(Foo something);
Or to keep it more general:
public IBar Method(IFoo something);
The question is what do you return on what kind of failure. the options would be:
- empty return type like: new List; or: new EmptyBar();
- null
- throw an exception
- a special list value indicating failure like: new List{new FailureBar()}
I really hate option 4 so I´m mostly interessted to hear when you use the other 3 options and why