1
我正在構建一個程序,將移動一堆文件。嘗試捕捉塊不阻止異常
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;
}
}
問題是我在運行程序時收到異常。有時文件不存在。
我該如何做到這一點,如果它失敗了,它只是輸出失敗,並繼續前進?
刪除罰球和日誌/警報 – InferOn
'一抓內部throw'沒有得到通過外抓掉,因此它仍然會在調試器內部中斷。 –
儘管不是失敗安全機制,但在執行副本之前添加一個File.Exists – Steve