Especially If the goal is guarantee "null in null out" for all arguments, it would be clearer to check them all for null up front. Then check NValue types and convert arguments to useful C++ types. Then implement the function logic in one stretch of code. Then convert the result to NValue.