No, it can be very helpful. For example: If you did not want to completely stop the loop, if an exception was thrown, or if additional code was added that should not be run for the current iteration due to the exception, you can do something like the following.
System.IO.DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo file in di.GetFiles()) { try { file.Delete(); } catch(System.IO.IOException) { Console.WriteLine("Please Close the following File {0}", file.Name); continue; }
That way, you can log the error so you can review it later, but still handle the rest of what you tried to handle.
source share