That’s what secure coding guidelines say to do. It’s called “input validation”. For example here’s Apple’s: https://developer.apple.com/library/archive/documentation/Se...
Especially important on methods called on launch, if a crash would cause a problem.
(Swift or other strongly typed language would help here.)