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.
java.text.ParseException
seems the most appropriate. If you want a runtime exception and not a checked one, IllegalArgumentException
is probably the most appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With