On Monday, 11 May 2026 at 04:18:33 UTC, Alex wrote:
Hi,
After too many years of thinking to try D, I'm creating a
simple directory scanner. However, I'm already getting some
"inconistencies" in Exception handling I'm confused by and
trying to debug.
I'm using Visual D on Windows. DMD 2.110
In the code below, if I leave the writeln(entry.name) or even
just writeln(".") uncommented, then I get a FileException for
permission-denied directories as expected.
If I comment these lines out, e.g. to add the entry.name to an
array, instead I get a Throwable std.file.FileException which
is not caught as a FileException or Exception.
Is this expected? How to best handle this?
I don't think commenting those lines should affect anything, but
I'm testing on Linux which may be different.
foreach (DirEntry entry; dirEntries(path, SpanMode.shallow))
`dirEntries` itself can throw:
Throws: FileException if the path directory does not exist or
read permission is denied.
So you need to wrap the `dirEntries` call in try/catch too for
when a subdirectory can't be read.