Bug 1802 – std.getopt.getopt returns bool; should be void
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-01-24T01:58:00Z
Last change time
2015-06-09T01:14:30Z
Assigned to
andrei
Creator
caron800
Comments
Comment #0 by caron800 — 2008-01-24T01:58:47Z
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.
Comment #1 by andrei — 2008-01-25T09:54:44Z
Duly noted. I'll change the signature as requested, and will roll the change in the next minor release.