FileException Inconsistency?

Nick Treleaven nick at geany.org
Mon May 11 15:52:11 UTC 2026


On Monday, 11 May 2026 at 11:11:07 UTC, Alex wrote:
> On Monday, 11 May 2026 at 10:40:27 UTC, Nick Treleaven wrote:
>> On Monday, 11 May 2026 at 04:18:33 UTC, Alex wrote:
>>>         catch (FileException fe) {
>>>             writeln("File Exception: ", fe);
>>
>> You might want to change `fe` to `fe.msg`, otherwise it will 
>> print the stack trace too, which is confusing.
>
> Thanks for your replies and tip on '.msg'.
>
> The code "works" but my concern is simply that the file 
> permission access error resuts in either a desirable 
> FileException if there's a writeln() around, or a brutish 
> Throwable std.file.FileException if there isn't a writeln() for 
> some reason.  Just seems very strange that the FileException 
> isn't created and handled the same both ways as I would expect.
>
> I don't think it should have to catch a Throwable and decode a 
> std.file.FileException into what looks like should be caught by 
> the catch (FileException fe) {} for the same error?

It's very strange if a `Throwable` prints `FileException` but it 
isn't a `FileException`.

The Windows implementation of DirEntry is:
```d
         @property string name() const pure nothrow return scope
         {
             return _name;
         }

         @property bool isDir() const pure nothrow scope
         {
             return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
         }
...
         @property uint attributes() const pure nothrow scope
         {
             return _attributes;
         }
...
         string _name; /// The file or directory represented by 
this DirEntry.
...
         uint  _attributes; /// The file attributes from 
WIN32_FIND_DATAW.

```
So calling any of those does not throw a Throwable, and calling 
`writeln(string)` should not either. So if you are correct (sorry 
I don't have Windows to hand to test), possibly there is a 
compiler bug. Can you try to come up with a minimal example that 
triggers the bug?


More information about the Digitalmars-d-learn mailing list