Search code examples
c#objectnullreturn

good practises null object return


I have a question about c# programming language, when a method returns an object, and for example I'm forced to return null, which is not clean code, what is the best practise to handle this? I dont want to return null.

EDIT

This was a question because it started as discussion on a software engineering class after reading Clean Code - Robert C. Martin 's book and it really came to my mind that trying to avoid this added unnecesary complexity to the design.


Solution

  • In case to signal "failed to create object" C++ class constructs throws exceptions for this purpose.

    Some languages / projects prefer to use exceptions more to keep happy-pass happier while others may not.