Throw an exception if incorrect string is supplied.