Given a bool
validation function that takes an argument and returns true
or false
based on argument's compliance to some internal rules:
if the argument is null
, should the function:
- return
false
- return
true
- do neither and simply raise a
ArgumentNullException
I would tend to believe the best practice is to raise the exception. I am however curious to hear others experience on the subject.
Given the sole choice of a bool
, I am personally tempted to return false
, but could see benefits in returning true
also, based on the context of the function's usage.
A null string for instance could be interpreted as empty and may be considered valid.
Are there best practice guidelines for this specific situation? I am looking for a guideline, like ones found in books like Code Complete.
Does it always need to be a case by case?