isDir won't throw FileException with dirEntries

Nick Treleaven nospam at example.com
Tue Aug 30 11:25:07 PDT 2011


On 30/08/2011 19:17, Jonathan M Davis wrote:
> On Tuesday, August 30, 2011 11:04 Nick Treleaven wrote:
>> On 30/08/2011 19:02, Nick Treleaven wrote:
>>> On 30/08/2011 18:54, Jonathan M Davis wrote:
>>>> On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
>>>>> Hi,
>>>>> With the attached source file on Windows, dmd 2.054, I'm not getting an
>>>>> exception when the path doesn't exist. If I uncomment the foreach line,
>>>>> the exception is thrown. Should I file this in bugzilla?
>>>>
>>>> So, what exactly is the problem? Is the issue that isDir isn't
>>>> throwing or
>>>> that dirEntries isn't throwing? isDir should definitely throw if the
>>>> path doesn't exist, but I'm not sure that dirEntries will.
>>>
>>> The problem is that isDir doesn't throw - the documentation says:
>>> "Throws: FileException if the given file does not exist."
>>>
>>> If I remove the foreach/dirEntries then isDir does throw.
>>
>> BTW, I meant to say 'comment the foreach line' in my first post, sorry
>> for the confusion...
>
> So, you're saying that
>
> import std.file;
>
> void main(string[] args)
> {
>   auto path = args[1];
>
>   if (!path.isDir())
>   {
>   }
>
>   //foreach (DirEntry f; dirEntries(path, SpanMode.depth))
>   {
>   }
> }
>
> fails to throw on your system, whereas
>
> import std.file;
>
> void main(string[] args)
> {
>   auto path = args[1];
>
>   if (!path.isDir())
>   {
>   }
>
>   foreach (DirEntry f; dirEntries(path, SpanMode.depth))
>   {
>   }
> }
>
> _does_ throw? If so, that's a compiler bug. The foreach should have _zero_
> effect on the statements before it - save for stuff like scope statements.

Actually the opposite - it works fine without the foreach. Anyway it 
seems fairly clear now that it is a compiler bug, I'll file it. Thanks 
for the info.


More information about the Digitalmars-d-learn mailing list