Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriate exception to throw when a parsing error occurs?

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.

like image 652
Martin Törnwall Avatar asked Jan 21 '12 09:01

Martin Törnwall


1 Answers

java.text.ParseException seems the most appropriate. If you want a runtime exception and not a checked one, IllegalArgumentException is probably the most appropriate.

like image 161
JB Nizet Avatar answered Nov 15 '22 22:11

JB Nizet