什么是System.IO.DirectoryNotFoundException
找不到文件或目錄的部件時引發的異常。
繼承關系
例子
using System; using System.IO; class Program { static void Main(string[] args) { try { // Specify a directory name that does not exist for this demo. string dir = @"c:\78fe9lk"; // If this directory does not exist, a DirectoryNotFoundException is thrown // when attempting to set the current directory. Directory.SetCurrentDirectory(dir); } catch (DirectoryNotFoundException dirEx) { // Let the user know that the directory did not exist. Console.WriteLine("Directory not found: " + dirEx.Message); } } }
說明
DirectoryNotFoundException
使用值為0x80070003 的 HRESULT COR_E_DIRECTORYNOTFOUND。 請注意, DirectoryNotFoundException
當 COM 互操作程序看到 HRESULT STG_E_PATHNOTFOUND (其值為0x80030003)時,也會引發此異常。
如果你的代碼沒有 PathDiscovery 權限,則此異常的錯誤消息可能只包含文件或目錄名稱,而不是完全限定的路徑。