1

I am building a program that will move a bunch of files.

 if (line.Contains("INSERT INTO BACKLOGITEM_ATTACHMENT VALUES")) { string AttachementID = line.Split(',', ')')[1]; string FileName = AttachementsDictionary[AttachementID]; string BacklogScrumID = BacklogLookupDictionary[AttachementID]; BacklogItem Story = BacklogItemDictionary[BacklogScrumID]; Product Product = ProductDictionary[Story.ProductScrumId]; string FileToCopy = "\\\\dxScrum01v\\ScrumWorksPro\\scrumworks\\data\\attachments\\product" + Story.ProductScrumId + "\\attachement" + AttachementID; string FileToSave = "C:\\ScrumWorksAttachementExport\\" + Product.ProductName + "\\" + Product.StoryPrefix + "-" + Story.StoryTitle + "\\" + FileName; //Console.WriteLine(FileToCopy + " >>> " + FileToSave); try { File.Copy(@FileToCopy, @FileToSave); } catch (Exception) { Console.WriteLine("Failed: " + FileToSave); throw; } } 

The issue is that I am getting an exception when running the program. There are times when the file does not exist.

How can I make it so that if it fails it just outputs the failure and keeps going? enter image description here

4
  • 6
    remove throw and log/alert Commented Oct 26, 2015 at 19:03
  • 3
    throw inside a catch does not get caught by the outer catch, so it will still break inside the debugger. Commented Oct 26, 2015 at 19:03
  • While not a fail safe mechanism add a File.Exists before executing the copy Commented Oct 26, 2015 at 19:04
  • By the way, there is no reason to use the @ in front of the variables, and you should be using it when you specify the file path (to avoid double backslashes). Commented Oct 26, 2015 at 19:17

1 Answer 1

3

Remove throw; if you dont want your application to break, you can handle the exception too

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.