Bug 15221 – Duration should treat division by 0 as a logic error rather than throwing an exception

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-18T22:39:00Z
Last change time
2015-10-18T22:40:44Z
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2015-10-18T22:39:49Z
Duration should never have checked for division by 0 and thrown a TimeException when it occurred. The OS/hardware already checks for that, and it should be considered a logic error. Checking for it and possibly throwing just slows the code down and makes it so that it can't be @nogc. This is technically a breaking change, but it will only break code which doesn't bother to avoid dividing by 0 and then catches TimeException when it occurs, and such code is likely extremely rare, if it exists at all. Given the fact that the odds of actually breaking code are extremely low and that this allows us to make Duration fully @nogc except for toString, I think that it's worth the risk.
Comment #1 by issues.dlang — 2015-10-18T22:40:44Z
Okay. The PR for this was already merged, but now it should show up in the changelog as requested in the github discussion for the PR. https://github.com/D-Programming-Language/druntime/pull/1405