關於異常System.IO.DirectoryNotFoundException


什么是System.IO.DirectoryNotFoundException

找不到文件或目錄的部件時引發的異常。

繼承關系

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 權限,則此異常的錯誤消息可能只包含文件或目錄名稱,而不是完全限定的路徑。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM