I have this piece of code:
try { var files = from folder in paths from file in Directory.EnumerateFiles(path, pattern, searchOption) select new Foo() { folder = folder, fileName = file }; Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, currentFile => { DoWork(currentFile); }); } catch (Exception ex) { }
When I have an exception in Directory.EnumerateFiles , I cannot catch this exception in this piece of code. An exception is the method that calls this fragment.
From Visual Studio in debug mode, the exception is thrown into Visual Studio (for example, DirectoryNotFoundException ).
source share