Utility function for fail-fast behaviour.
Much performance is lost by methods which allow many different types of inputs.
Checking the input and throwing an error immediately makes better overall code.