Adding exception handling and correcting the ValueError raise