Continue iteration after exception

Josh moonburntm at gmail.com
Wed Jan 23 06:50:52 PST 2013


DMD 2.060, Windows 7 64-bit

Source:

import std.file;
import std.stdio;

void main()
{
     foreach (DirEntry d; dirEntries("C:\\", SpanMode.breadth))
         writeln(d.name);
}

This code stops with "std.file.FileException at std\file.d(2434): 
C:\Documents and Settings: Access is denied." when it gets to 
C:\Documents and Settings. On Windows 7 that doesn't actually 
exist, which is fine. What I'd like it to do is tell me that it 
doesn't exist, but continue iterating anyway. I've tried 
try-catch, but that just stops the iteration.

Any help is appreciated. Thanks :)

Josh


More information about the Digitalmars-d-learn mailing list