Bug 6410 – Few common exceptions in std.exception

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-30T07:04:25Z
Last change time
2018-09-26T18:44:53Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-07-30T07:04:25Z
I am not fond of deep hierarchies of exceptions, because it's hard to remember them all, and use/catch them well. On the other hand there are very common exceptions that I think are worth having in a standard library, inside std.exception, as compromise. A rough list (surely to be improved, and maybe few more to be added): ArgumentException thrown when an argument is wrong or out of bound EmptyException thrown when applied on an empty item/collection IndexException thrown tipically on out of bound situations IOException thrown by File in error situations KeyException thrown by library-defined associative/sets when a key is missing. MissingMethodException thrown by ? OverflowException thrown on detected underflow/overflow situations (by to!() too?) IotaException thrown on errors in iota() function UncomparableException thrown by user-defined opCmp() of classes
Comment #1 by lt.infiltrator — 2014-03-19T19:16:31Z
This sounds like a great idea. The only change I'd suggest is from UncomparableException to IncomparableException.
Comment #2 by razvan.nitu1305 — 2017-07-07T16:57:34Z
Actually, I think NotComparable is the best pick.
Comment #3 by issues.dlang — 2017-07-08T05:25:32Z
I'm very tempted to close this as "won't fix." Here's a semi-recent discussion on this issue: http://forum.dlang.org/post/[email protected] and this is probably my best post in there about why general exception types like this are a bad idea: http://forum.dlang.org/post/[email protected] Andrei did not weigh in on the topic, but Walter was in clear agreement with me that this sort of approach is a bad idea.
Comment #4 by dlang-bugzilla — 2017-07-08T11:09:17Z
I think the only good idea from bearophile's list is OverflowException, as conversion data often comes from user input, and it may be useful to distinguish values that are syntactically correct but simply too large to be represented in the program's chosen data type, from values that are syntactically incorrect.
Comment #5 by greeenify — 2017-07-08T11:30:28Z
FYI there will be HttpStatusException soon: https://github.com/dlang/phobos/pull/5551
Comment #6 by issues.dlang — 2017-07-09T00:08:04Z
(In reply to greenify from comment #5) > FYI there will be HttpStatusException soon: > https://github.com/dlang/phobos/pull/5551 Yeah, but it's not generic. It's derived from std.net.curl.CurlException and really only makes sense for std.net.curl. It's not something that another library like vibe.d would use.
Comment #7 by pro.mathias.lang — 2018-09-26T18:44:53Z
Given the discussion, the nature of the report (enhancement) and the lack of activity, I think it's time to close this one as WONTFIX.