diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d5d8c8ad..e49265bd 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -43,6 +43,7 @@ Fix incorrect method name 'withFirstRowAsHeader' in user guide. Negative numeric values in the first column are always quoted in minimal mode. Update platform requirement from Java 6 to 7. + Do not use RuntimeException in CSVParser.iterator().new Iterator() {...}.getNextRecord() CSVParser: Add factory method accepting InputStream. Add convenience API CSVFormat.print(File, Charset) Add convenience API CSVFormat.print(Path, Charset) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index f5829cc0..410e6a4d 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -501,10 +501,14 @@ public final class CSVParser implements Iterable, Closeable { /** * Returns an iterator on the records. * - *

IOExceptions occurring during the iteration are wrapped in a - * RuntimeException. - * If the parser is closed a call to {@code next()} will throw a - * NoSuchElementException.

+ *

+ * An {@link IOException} caught during the iteration are re-thrown as an + * {@link IllegalStateException}. + *

+ *

+ * If the parser is closed a call to {@link Iterator#next()} will throw a + * {@link NoSuchElementException}. + *

*/ @Override public Iterator iterator() { @@ -515,8 +519,8 @@ public final class CSVParser implements Iterable, Closeable { try { return CSVParser.this.nextRecord(); } catch (final IOException e) { - // TODO: This is not great, throw an ISE instead? - throw new RuntimeException(e); + throw new IllegalStateException( + e.getClass().getSimpleName() + " reading next record: " + e.toString(), e); } }