gbif / gbif-common

Utility classes
Apache License 2.0
1 stars 1 forks source link

UnknownDelimitersException - make it a checked exception? #2

Closed kbraak closed 6 years ago

kbraak commented 7 years ago

@cgendreau @mdoering

UnknownDelimitersException is an unchecked exception in gbif-common (a duplicate copy UnkownDelimitersException exists in dwca-io and can likely be removed).

This exception gets thrown when a CSV file is inspected for its delimiter, however, the delimiter cannot be determined. This exception can be cause when reading an empty CSV file for example.

extractCsvMetadata() inside CSVReaderFactory specifies UnknownDelimitersException in its signature. Various other build() methods inside this class also call extractCsvMetadata(), however, do NOT specify it in their own signature.

Since the file has been considered invalid, why not declare it in the signature and give the client the chance to recover from it? This is the way that UnsupportedArchiveException is handled in dwca-io, which is a similar unchecked exception that always appears in the method signature.

Apart from this issue of consistency, I wonder if UnknownDelimitersException and UnsupportedArchiveException wouldn't be better made into checked exceptions?

cgendreau commented 7 years ago

thanks @kbraak They both will be changed to checked exceptions.

MattBlissett commented 6 years ago

Maybe it's reasonable to make UnknownDelimitersException a subclass of IOException, which will already be handled.

give the client the chance to recover from it?

Nothing stops the client from catch (RuntimeException e) or a subclass already, it's just optional.

cgendreau commented 6 years ago

Sounds good