In the below lines of code ,I am calling validatePersonDTO method inside a while loop.I need to return back to while loop to process next record if any error occurs within validatePersonDTO’s methods for the current record.
Note:
ValidatepersonDTo method is in another class from where the while loop exists.
This is a very basic question , i have tried out some options , but neither continue or return wouldn’t work.
So kindly let me know of your suggestions.
while ((nextLine = reader.readNext()) != null) {
hrUploadValidator.validatePersonDTO(personDTO);
}
public void validatePersonDTO(PersonDTO personDTO) {
try {
validateCdsId(personDTO, logDTO,regionIdList);
validateEmpFirstName(personDTO, logDTO);
validateEmpLastName(personDTO, logDTO);
validateEffectiveIn(personDTO, logDTO);
}
Assuming that
validatePersonDTOthrows an exception when validation fails (it’s the only option, since the method isvoid), you are missing a try/catch block inside yourwhileloop:Once the exception is logged or otherwise processed in the
catchblock, your loop will continue its iterations from where it left off.