View Javadoc
1   package com.opencsv.bean.exceptionhandler;
2   
3   import com.opencsv.bean.CsvToBean;
4   import com.opencsv.bean.StatefulBeanToCsv;
5   import com.opencsv.exceptions.CsvException;
6   
7   /**
8    * This interface defines a generic way of dealing with exceptions thrown
9    * during the creation of beans or their conversion to CSV output.
10   * @author Andrew Rucker Jones
11   * @since 5.2
12   */
13  @FunctionalInterface
14  public interface CsvExceptionHandler {
15  
16      /**
17       * <p>Determines how opencsv will handle exceptions that crop up during
18       * bean creation or writing.
19       * There are three ways of dealing with an exception:</p>
20       * <ol>
21       *     <li>Ignore the exception. In this case, return {@code null}.</li>
22       *     <li>Queue the exception. In this case, return either the original
23       *     exception thrown, or a new exception that meets your needs better.</li>
24       *     <li>Halt processing by throwing the exception. In this case, throw
25       *     the exception or a new exception that meets your needs better.</li>
26       * </ol>
27       * <p>Please be cautioned: Due to the multi-threaded nature of opencsv's
28       * conversion routines, there is no guarantee that the exception thrown,
29       * if your chosen error handler throws exceptions, is the error in the
30       * input that would have caused the exception to be thrown if the input
31       * were processed in strict sequential order. That is, if there are four
32       * errors in the input and your error handler queues the first three but
33       * throws the fourth, the exception thrown might relate to <em>any</em>
34       * of the four errors in the input.</p>
35       * <p>If your exception handler queues a certain number of exceptions
36       * before throwing one, opencsv makes a best-faith effort to make sure all
37       * of the exceptions marked for queueing are actually available via
38       * {@link CsvToBean#getCapturedExceptions()} or
39       * {@link StatefulBeanToCsv#getCapturedExceptions()} after processing,
40       * but there are no absolute guarantees.</p>
41       * <p>This method must be thread-safe.</p>
42       * @param e The exception that was thrown
43       * @return The exception to be queued, or {@code null} if the exception
44       *   should be ignored
45       * @throws CsvException If a halt to all processing is desired
46       */
47      CsvException handleException(CsvException e) throws CsvException;
48  }