尝试Catch Block不会阻止异常

时间:2015-10-26 19:02:07

标签: c# try-catch

我正在构建一个移动大量文件的程序。

            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;
                }

            }

问题是我在运行程序时遇到异常。有时文件不存在。

我怎样才能这样做,如果它失败了它只输出失败并继续前进? enter image description here

1 个答案:

答案 0 :(得分:3)

如果您不希望应用程序中断,请删除throw;,您也可以处理异常