如果我在执行 foreach 期间发现异常,我可以继续执行吗?
foreach (string d in Directory.GetDirectories(path))
{
try
{
foreach (string f in Directory.GetFiles(path))
{
//do something
}
//do something
}
catch
{
// If there is an error in the foreach, I want it to keep on going
}
}
我问这个是因为它在foreach
获取所有文件之前突然终止。