[Interest] Args

Till Oliver Knoll till.oliver.knoll at gmail.com
Sun May 7 20:46:58 CEST 2017



> Am 04.05.2017 um 05:44 schrieb Igor Mironchik <igor.mironchik at gmail.com>:
> 
> 
> 
> 2017-05-04 11:41, Konstantin Tokarev пишет:
>> Using exceptions in arguments parser is something that just cannot be justified.
>> 
> 
> Why not?

Even in the danger of starting a huge debate about "exceptions vs return error code" here are my thoughts about it:

Exceptions should just be used for... well, /exceptional/ cases.

So what would be an "exceptional case" for a command line parser then? Certainly not wrongly provided arguments. Humans tend to misspell words all the time, so that's "the norm": business as usual for a command line parser to validate the input and inform the user appropriately (with a usage help, similar spelled commands etc.). Nothing which cries "exception!" here IMHO.

The only thing I could think of in a 10 second brainstorming which could be considered "exceptional" is when e.g. "stdin" (or some socket even from which to read commands, but even this would be a bordercase, as it could be considered "normal" that a socket cannot be opened) cannot be opened for reading (which is somewhat a constructed example, as arguments are usually passed as input parameters to main() anyway - but you get the idea).

The internet is full of articles - and opinions - about when to use exceptions, and when not (and we haven't even touched the topic of "unchecked vs checked exceptions" - at least in the Java camp that's all the rage ;)).

Cheers,
  Oliver


More information about the Interest mailing list