3

如果我调用System.IO.File.Delete()并传递一个目录名,我会得到一个目录名,UnauthorizedAccessException尽管问题与任何类型的权限无关,我想InvalidOperationException在这里会更合适。

为什么会抛出这个特定的异常?这是设计错误还是有任何原因?

4

1 回答 1

4

No idea, but it smells like a design fault because the Directory.Delete has a different behavior that File.Delete. Directory.Delete will throw a DirectoryNotFoundException if the path actually refers to a file instead of directory. One would expect that the same kind of exception would be thrown in these two cases.

于 2012-12-11T09:22:52.727 回答