Bug 13620 – Consolidate / clean up exception types used for OS exceptions

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-15T15:44:50Z
Last change time
2024-12-01T16:22:43Z
Keywords
pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Moved to GitHub: phobos#10093 →

Comments

Comment #0 by dlang-bugzilla — 2014-10-15T15:44:50Z
Currently, Phobos is inconsistent in how it implements exceptions caused by OS errors: - std.file declares an exception type specific to the module (FileException), even though there is no technical reason why a file operation is treated differently than other I/O or OS operations. - Some modules (e.g. std.mmfile, std.process) "borrow" these exception types despite not actually using functionality in std.file. - Whether a certain Phobos function uses a C function or an OS API to implement something is an implementation detail. Documenting whether an ErrnoException or some other exception type is thrown is an abstraction leak. - Some functions (e.g. Clock.currTime) throw different, unrelated exception types on different platforms. - Because of all the confusion, occasionally the incorrect exception type is used (e.g. passing GetLastError to strerror). A notable example is FileException, which interprets the error code differently depending on the platform. To remedy the situation, I suggest: 0. Define WindowsException and wenforce, in the style of ErrnoException and cenforce (already done). 1. Define an abstract std.exception.OSException class, derived from Exception. This class has an "errno" field, the meaning of which depends on the subclass. 2. Make ErrnoException and WindowsException subclasses of OSException. 3. Replace FileException with an alias to OSException. 4. Update all documentation which mentions FileException to use OSException instead. 5. Review all uses of FileException, ErrnoException and other thrown exceptions thrown on OS error conditions to use ErrnoException/cenforce and WindowsException/wenforce as appropriately. This should clean things up without breaking any code.
Comment #1 by dlang-bugzilla — 2014-10-15T17:05:28Z
Correction: s/cenforce/errnoEnforce/. errnoEnforce is a public function in std.exception. We should use that where appropriately. cenforce is a private function declared in std.file. It needs to be replaced with errnoEnforce.
Comment #2 by dlang-bugzilla — 2014-10-15T17:45:04Z
Also, kill std.stdio.wenforce (which is private), as discussed in issue 13542.
Comment #3 by dlang-bugzilla — 2014-10-15T18:31:56Z
Another FileException clone for the chopping block: StdioException
Comment #4 by dlang-bugzilla — 2014-10-15T19:34:18Z
And another: std.process.ProcessException
Comment #5 by dlang-bugzilla — 2014-10-15T20:08:12Z
Comment #6 by robert.schadek — 2024-12-01T16:22:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10093 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB