Class ExceptionHandlerIgnoreThenThrowAfter

  • All Implemented Interfaces:
    CsvExceptionHandler

    public final class ExceptionHandlerIgnoreThenThrowAfter
    extends java.lang.Object
    implements CsvExceptionHandler
    An exception handler that ignores the first x exceptions, then throws any further exceptions.
    Since:
    5.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicInteger count  
      private int maxExceptions  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CsvException handleException​(CsvException e)
      Determines how opencsv will handle exceptions that crop up during bean creation or writing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • count

        private final java.util.concurrent.atomic.AtomicInteger count
      • maxExceptions

        private final int maxExceptions
    • Constructor Detail

      • ExceptionHandlerIgnoreThenThrowAfter

        public ExceptionHandlerIgnoreThenThrowAfter​(int maxExceptions)
        Creates an instance.
        Parameters:
        maxExceptions - The number of exceptions that will be ignored. Any exception handled after this limit will be thrown.
    • Method Detail

      • handleException

        public CsvException handleException​(CsvException e)
                                     throws CsvException
        Description copied from interface: CsvExceptionHandler

        Determines how opencsv will handle exceptions that crop up during bean creation or writing. There are three ways of dealing with an exception:

        1. Ignore the exception. In this case, return null.
        2. Queue the exception. In this case, return either the original exception thrown, or a new exception that meets your needs better.
        3. Halt processing by throwing the exception. In this case, throw the exception or a new exception that meets your needs better.

        Please be cautioned: Due to the multi-threaded nature of opencsv's conversion routines, there is no guarantee that the exception thrown, if your chosen error handler throws exceptions, is the error in the input that would have caused the exception to be thrown if the input were processed in strict sequential order. That is, if there are four errors in the input and your error handler queues the first three but throws the fourth, the exception thrown might relate to any of the four errors in the input.

        If your exception handler queues a certain number of exceptions before throwing one, opencsv makes a best-faith effort to make sure all of the exceptions marked for queueing are actually available via CsvToBean.getCapturedExceptions() or StatefulBeanToCsv.getCapturedExceptions() after processing, but there are no absolute guarantees.

        This method must be thread-safe.

        Specified by:
        handleException in interface CsvExceptionHandler
        Parameters:
        e - The exception that was thrown
        Returns:
        The exception to be queued, or null if the exception should be ignored
        Throws:
        CsvException - If a halt to all processing is desired