View Javadoc
1   package com.opencsv.bean.exceptionhandler;
2   
3   import com.opencsv.exceptions.CsvException;
4   
5   import java.util.concurrent.atomic.AtomicInteger;
6   
7   /**
8    * An exception handler that ignores the first x exceptions, then throws any
9    * further exceptions.
10   * @author Andrew Rucker Jones
11   * @since 5.2
12   */
13  final public class ExceptionHandlerIgnoreThenThrowAfter implements CsvExceptionHandler {
14  
15      private final AtomicInteger count = new AtomicInteger();
16      private final int maxExceptions;
17  
18      /**
19       * Creates an instance.
20       * @param maxExceptions The number of exceptions that will be ignored. Any
21       *                      exception handled after this limit will be thrown.
22       */
23      public ExceptionHandlerIgnoreThenThrowAfter(int maxExceptions) {
24          this.maxExceptions = maxExceptions;
25      }
26  
27      @Override
28      public CsvException handleException(CsvException e) throws CsvException {
29          if(count.incrementAndGet() > maxExceptions) {
30              throw e;
31          }
32          return null;
33      }
34  }