Is there an appropriate exception class for invalid command line arguments in the Java API or do I have to create my own? I’ve tried searching for one but can’t find any in the API.
This is for an assignment so I cannot use third party libraries for command line parsing.
The best way to handle unknown command line parameters or combinations that don’t make sense to the program is to display an error message and offer a usages output.
Personally, depending on the complexity of the command line, I will create a method called “usage” (usually static) that can have an optional error message passed to it.
While parsing the command line parameters passed into the program, I will call this method and either exit, via a flag or directly, or have
usagemethod call exit for me.But that’s just me