I have a windows forms ap that will be for indexing file collections. I am using the .net DirectorySearcher, which implements an UnauthorizedAccessException. Problem with the following code is, the exception actually occurs within the foreach statement, so when an exception is thrown, the loop stops processing. How can I catch the exception and keep the loop working? Should I keep a counter and tell it to start at the next position from the last position after it catches the exception repeating this until it's finished? Here's the code in question: