tags:

views:

26

answers:

1

How would I go about saving several files and log the errors when something bad happens, but then keep going with the next file in sequence? Essentially I will have a collection of pdf-files that I want to save at a certain location. If an error is thrown when a file is process, the error should be logged and then the saving should continue with the next file in the sequence? This is still in the planning stages, so I don't have any code to share. I just wanted to get some input on what solutions would be suitable and heads-up on any pitfalls.

+4  A: 

You can do it like this.

foreach (var file in files)
{
    try
    {
        // Save the file
    }
    catch (Exception e)
    {
        // Log exception
        Console.WriteLine(e.Message);
        // Do not re-throw the exception
    }
    continue;
}
Alexander
Thank you Alexander. Looks straightforward enough. :) I'll see if any other suggestions come in before marking it as accepted.
daft