Appropriate exception to throw when a parsing error occurs?
10,462
java.text.ParseException
seems the most appropriate. If you want a runtime exception and not a checked one, IllegalArgumentException
is probably the most appropriate.
Author by
Martin Törnwall
Updated on June 20, 2022Comments
-
Martin Törnwall almost 2 years
When parsing a custom (text) file format in Java, what is the appropriate exception to throw when a syntax error is encountered? I'm looking for something analogous to .NET's FormatException.
Edit: The part about parsing might be slightly misleading. What I'm doing is not so much parsing as reading a line from a file, passing it to a method that extracts colon-separated fields from it, hence why I thought FormatException would be appropriate.