public final class ExceptionHandlerQueueThenThrowAfter extends Object implements CsvExceptionHandler
An exception handler that queues the first x exceptions, then throws any further exceptions.
Note: when testing this on systems with a high number of cores/threads under load we noted discrepancies between the number of exceptions counted and the number exceptions queued. If it is actually important to see the exceptions thrown then we would heavily recommend you use the single threaded iterator() in CsvToBean and collecting the exceptions yourself.
Constructor and Description |
---|
ExceptionHandlerQueueThenThrowAfter(int maxExceptions)
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
CsvException |
handleException(CsvException e)
Determines how opencsv will handle exceptions that crop up during
bean creation or writing.
|
public ExceptionHandlerQueueThenThrowAfter(int maxExceptions)
maxExceptions
- The number of exceptions that will be queued. Any
exception handled after this limit will be thrown.public CsvException handleException(CsvException e) throws CsvException
CsvExceptionHandler
Determines how opencsv will handle exceptions that crop up during bean creation or writing. There are three ways of dealing with an exception:
null
.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.
handleException
in interface CsvExceptionHandler
e
- The exception that was thrownnull
if the exception
should be ignoredCsvException
- If a halt to all processing is desiredCopyright © 2005–2023. All rights reserved.