关于异常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