Should a check for null occur before making the call to a function or within the function itself?
Where to check for null, in calling method or in function?
null
Related Question
- C# – In C#, what happens when you call an extension method on a null object
- Javascript – How to check for an undefined or null variable in JavaScript
- Java – Is null check needed before calling instanceof
- JavaScript checking for null vs. undefined and difference between == and ===
- Javascript – standard function to check for null, undefined, or blank variables in JavaScript
- Javascript – How to check for null values in JavaScript
- .net – How to check if a string is null or empty in PowerShell
Best Solution
I would say within the call itself. That way, you only check for null in one place, not 5 places if you call that function from 5 different spots.
But this isn't a for sure answer. It really depends on the function and what the consequences are of calling it with a null argument.