0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00

nf: TextImporter - add UnknownDelimiterException

Allows users to handle this exception separately
This commit is contained in:
David Allison 2021-08-22 18:55:35 +01:00 committed by Mike Hardy
parent cab199935a
commit dfc4e43bd8

View File

@ -101,7 +101,10 @@ public class TextImporter extends NoteImporter {
return notes;
}
/** Number of fields. */
/**
* Number of fields.
* @throws UnknownDelimiterException Could not determine delimiter (example: empty file)
*/
@Override
public int fields() {
open();
@ -147,13 +150,13 @@ public class TextImporter extends NoteImporter {
}
if (mDialect == null && mDelimiter == '\0') {
throw new RuntimeException("unknownFormat");
throw new UnknownDelimiterException();
}
}
@Contract(" -> fail")
private void err() {
throw new RuntimeException("unknownFormat");
throw new UnknownDelimiterException();
}
private void updateDelimiter() {
@ -284,4 +287,10 @@ public class TextImporter extends NoteImporter {
return Files.lines(Paths.get(mFile.getAbsolutePath()), StandardCharsets.UTF_8);
}
}
public static class UnknownDelimiterException extends RuntimeException {
public UnknownDelimiterException() {
super("unknownFormat");
}
}
}