1

I am using BeanIO to convert flat file into list of Object. Using following code snippet.

while ((MyCustomRecord obj = (MyCustomRecord) in.read()) != null) {
         System.out.println(obj);
}

But problem with this is, if exception occurs during parsing of some record, It immediately stops processing records. I want to suppress such exception and want it to continue processing of next records.

Is there a way to do this?

One thing that I can try is to put in.read in body of while block and wrap it around try/catch but then how would I detect end condition. There seems to be no method that tells end of records.

Thanks Jitendra

RandomQuestion
  • 6,778
  • 17
  • 61
  • 97

1 Answers1

4

Found answer in BeanIO reference documentation. I missed that earlier.

It can be done by registering your custom ErrorHandler in BeanReader.

in.setErrorHandler(new BeanReaderErrorHandlerSupport() {
            public void invalidRecord(InvalidRecordException ex) throws Exception {
                System.out.println(ex.getLocalizedMessage());
            } 
});

http://beanio.org/docs/reference/index.html#StreamValidation

RandomQuestion
  • 6,778
  • 17
  • 61
  • 97