Register to Better Coder! It's free.
Enjoy the premium features and succeed at every job interview.

BP12: Parameter validation

If your function takes parameters and the function cannot work without valid values, put in guard clauses at the start and throw an exception if they are not something you expect. ie, for null parameters throw a ArgumentNullException(nameof(param)) to indicate whats wrong. Don't let the function crash midway though or even worse, return the wrong result.

Comments

No Comments Yet.
Be the first to tell us what you think.

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play