Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate / clean up exception types used for OS exceptions #10093

Open
dlangBugzillaToGithub opened this issue Oct 15, 2014 · 5 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

dlang-bugzilla (@CyberShadow) reported this on 2014-10-15T15:44:50Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=13620

Description

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.
@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2014-10-15T17:45:04Z

Also, kill std.stdio.wenforce (which is private), as discussed in issue 13542.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2014-10-15T18:31:56Z

Another FileException clone for the chopping block: StdioException

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2014-10-15T19:34:18Z

And another: std.process.ProcessException

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2014-10-15T20:08:12Z

https://github.com/D-Programming-Language/phobos/pull/2616

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants