如果我调用System.IO.File.Delete()
并传递一个目录名,我会得到一个目录名,UnauthorizedAccessException
尽管问题与任何类型的权限无关,我想InvalidOperationException
在这里会更合适。
为什么会抛出这个特定的异常?这是设计错误还是有任何原因?
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.