Summary: Add GetOptException (or similar) to std.getopt
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Jonathan M Davis <> 2010-11-16 19:20:35 
PST ---
Right now, if there's a problem with std.getopt, you typically either get a
regular Exception or a ConvError (soon to be ConvException). This makes it a
bit cumbersome to specifically grab errors pertaining to problems parsing
command-line arguments. Having an Exception thrown for doing something like
passing an empty array to getopt() probably makes some sense, but ideally,
there would be a specific exception type for problems involving parsing
command-line arguments - such as GetOptException, or something similar.

What would also be particularly useful is if GetOptException gave you specific
information about the error beyond just toString(). Being able to get at the
specific error message without any stack trace would be nice. In particular,
knowing which option it was trying to get when it failed would be useful.

Right now, if getopt fails, you either catch any and all exceptions (and
errors, thanks to ConvError) and have to somehow figure out what went wrong to
somehow print a useful error message (or just print a generic error message),
or you have to let the exception escape and have it be printed. And while have
the exception be printed is fine for quick scripts and the like, for end-user
applications, the user shouldn't be seeing stack traces or exception messages
which include source file names and the like. You should be able to print
intelligent errors about what they entered incorrectly. And right now, you
can't do that.

So, I'd like GetOptException to be added and then used for all errors
pertaining to problems parsing the command-line options and which aren't
programmer errors  (such as passing an empty array). Also, I'd like it to give
enough information to be able to easily print out exactly what went wrong - in
particular, which option failed to be handled correctly and why.

std.getopt.getopt is extremely useful, but it needs better error reporting if
it's going to be used for serious applications.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to