瀏覽代碼

Better exception error on File.Replace exception

Brad Robinson 7 年之前
父節點
當前提交
e81f95c0cd
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      PetaJson.cs

+ 8 - 1
PetaJson.cs

@@ -148,7 +148,14 @@ namespace PetaJson
                     }
 
                     // Replace it
-                    File.Replace(tempName, filename, backupFilename);
+                    try
+                    {
+                        File.Replace(tempName, filename, backupFilename);
+                    }
+                    catch (System.IO.IOException x)
+                    {
+                        throw new System.IO.IOException(string.Format("Failed to replace temp file {0} with {1} and backup {2}, reason {3}", tempName, filename, backupFilename, x.Message), x);
+                    }
                 }
                 else
                 {