[Issue 1802] New: std.getopt.getopt returns bool; should be void

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 23 23:58:48 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1802

           Summary: std.getopt.getopt returns bool; should be void
           Product: D
           Version: 2.010
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: caron800 at googlemail.com


D's error handling policy, as documented at 
http://digitalmars.com/d/2.0/errors.html, says that functions should throw
exceptions on error, not return a pass/fail code.

However, getopt throws no exception on error, but instead returns true for
success and false for failure. This means that calling code must do lots of
ugly checking of the return code. Further, if it returns false, there is no way
to find out why it failed, wheras an exception could carry that information.

To make matters worse, the meaning of the bool return value is not documented!
So the only way to find out that you even /need/ to do error checking is to
read the source code (which is, by definition, an implementation detail, not
the API).

getopt should return void. In the event of an error, an exception should be
thrown.


-- 



More information about the Digitalmars-d-bugs mailing list