added validation method to perform the check and throw the error