开发者

File.Copy method

Is it posiible that the following code doesn't throw any exception and doesn't cop开发者_开发技巧y files?

void Copy2(string from, string to)
{
    lock (_thisLock)
    {
     if (File.Exists(from))
     {
      File.Copy(from, to, true);
      return;
     }
     Logger.Write("File does not exists");
    }
}

Customer says that the application doesn't crash and doesn't copy any file, and doesn't write log. Logger's type is Microsoft.Practices.EnterpriseLibrary.Logging.Logger.


Sure, if the file doesn't exist - (!File.Exists) - then the File.Copy call won't get reached.

Logger.Write does not count as an exception.

If, as your update suggests, there is nothing in the logs, I would double check the Logger.Write function. Is it implemented correctly? Is there an exception being thrown and handled within that method? That would be more likely than File.Copy failing without throwing an exception.


If the file doesn't exist and no logger appenders have been configured, then the situation you describe may occur - i.e. no error, no logging


looking at MSDN for File.Copy you can see that it throws quite a few exceptions. Make you that anything capturing the exception above the stack is handling that exception/error properly and not simply swallowing it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜