dirEntries throws exception on broken symlinks

FreeSlave freeslave93 at gmail.com
Sun Jan 5 13:33:54 PST 2014


You must not cast base class to derived class, when you don't 
know actual type (and even if you know exact type it's still bad 
practice to cast instance of more generic type to more specific 
one). Use multiple catch statements instead:

catch(FileException o)
{
//handle FileException
}
catch(Exception o)
{
//handle all other types of exceptions
}

About dirEntries, you need to move your try/catch statements into 
loop somehow. You probably should save result of dirEntries to 
variable and then make manual loop instead of foreach. Result of 
dirEntries is lazy, so it will not throw exception when you just 
get it.

It may look like

auto entries = dirEntries(your args);
while(!entries.empty)
{
     try
     {
         entry = entries.front;
         //do your stuff
     }
     //"catch" statements
     finally
     {
         entries.popFront();
     }
}


More information about the Digitalmars-d-learn mailing list