Thread overview
[Issue 1802] New: std.getopt.getopt returns bool; should be void
Jan 24, 2008
d-bugmail
Jan 25, 2008
d-bugmail
Jan 25, 2008
d-bugmail
Mar 07, 2008
d-bugmail
Mar 07, 2008
d-bugmail
Mar 07, 2008
d-bugmail
January 24, 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@digitalmars.com
        ReportedBy: caron800@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.


-- 

January 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1802


andrei@metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED




------- Comment #1 from andrei@metalanguage.com  2008-01-25 09:54 -------
Duly noted. I'll change the signature as requested, and will roll the change in the next minor release.


-- 

January 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1802


andrei@metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla@digitalmars.com    |andrei@metalanguage.com
             Status|ASSIGNED                    |NEW




-- 

March 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1802


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla@digitalmars.com  2008-03-07 00:24 -------
Fixed dmd 2.012


-- 

March 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1802


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




-- 

March 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1802


andrei@metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




--