This has problems:
1. GetLastError() is not the same as errno, although D also has errno. So there's confusion and wrong documentation about the arguments.
2. FileException is never called by anyone other than std.file, so the constructor should be marked private.
3. The call to GetLastError() should be moved into the constructor body, in order to reduce bloat (i.e. having code for it generated over and over at the call site).
Comment #1 by dlang-bugzilla — 2014-09-28T02:22:18Z
(In reply to Vladimir Panteleev from comment #1)
> Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c2 , we
> should look into replacing uses of FileException / GetLastError with
> wenforce.
wenforce is currently private and throws an Exception, which would break code that looks for FileException.
While reengineering the interface has its place, this bug report is only about fixing the existing code and the way it works.
Comment #3 by dlang-bugzilla — 2014-09-29T10:04:55Z
(In reply to Walter Bright from comment #2)
> wenforce is currently private
No.
> and throws an Exception,
No. It throws a WindowsException.
> which would break code that looks for FileException.
Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c6 we should introduce OSException make FileException an alias of OS
> While reengineering the interface has its place, this bug report is only
> about fixing the existing code and the way it works.
I suggest fixing the existing code without breaking it. Why do you think I suggested otherwise?
Comment #4 by bugzilla — 2014-10-04T09:54:09Z
(In reply to Vladimir Panteleev from comment #3)
> (In reply to Walter Bright from comment #2)
> > wenforce is currently private
>
> No.
>
> > and throws an Exception,
>
> No. It throws a WindowsException.
Then it has changed recently? stdio.d line 961:
private static T wenforce(T)(T cond, string str)
{
import std.windows.syserror;
if (cond) return cond;
throw new Exception(str ~ ": " ~ sysErrorString(GetLastError()));
}
>
> > which would break code that looks for FileException.
>
> Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c6 we
> should introduce OSException make FileException an alias of OS
>
> > While reengineering the interface has its place, this bug report is only
> > about fixing the existing code and the way it works.
>
> I suggest fixing the existing code without breaking it. Why do you think I
> suggested otherwise?
Because I thought you suggested throwing a different error than FileException. IF that is incorrect, then I was wrong.
Comment #5 by dlang-bugzilla — 2014-10-04T14:18:19Z
(In reply to Walter Bright from comment #4)
> (In reply to Vladimir Panteleev from comment #3)
> > No. It throws a WindowsException.
>
> Then it has changed recently? stdio.d line 961:
Oh, that's a completely different wenforce (which I also added a while ago, and forgot about). It should be changed to use the new one, in std.windows.syserror.
> > I suggest fixing the existing code without breaking it. Why do you think I
> > suggested otherwise?
>
> Because I thought you suggested throwing a different error than
> FileException. IF that is incorrect, then I was wrong.
My suggestion was to make FileException an alias of OSException, so no code will break (unless it compares the class name string from classinfo or something).
Comment #6 by dlang-bugzilla — 2014-10-15T15:45:31Z
(In reply to Vladimir Panteleev from comment #5)
> My suggestion was to make FileException an alias of OSException, so no code
> will break (unless it compares the class name string from classinfo or
> something).
Elaborated: https://issues.dlang.org/show_bug.cgi?id=13620
Comment #7 by robert.schadek — 2024-12-01T16:22:30Z