Issue 13620 - Consolidate / clean up exception types used for OS exceptions
Summary: Consolidate / clean up exception types used for OS exceptions
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2014-10-15 15:44 UTC by Vladimir Panteleev
Modified: 2024-12-01 16:22 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2014-10-15 15:44:50 UTC
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 Vladimir Panteleev 2014-10-15 17:05:28 UTC
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 Vladimir Panteleev 2014-10-15 17:45:04 UTC
Also, kill std.stdio.wenforce (which is private), as discussed in issue 13542.
Comment 3 Vladimir Panteleev 2014-10-15 18:31:56 UTC
Another FileException clone for the chopping block: StdioException
Comment 4 Vladimir Panteleev 2014-10-15 19:34:18 UTC
And another: std.process.ProcessException
Comment 5 Vladimir Panteleev 2014-10-15 20:08:12 UTC
https://github.com/D-Programming-Language/phobos/pull/2616
Comment 6 dlangBugzillaToGithub 2024-12-01 16:22:43 UTC
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