DirectoryNotFoundException 构造函数

定义

使用 DirectoryNotFoundException 类的消息字符串初始化 DirectoryNotFoundException 类的新实例。

重载

名称 说明
DirectoryNotFoundException()

初始化类的新实例 DirectoryNotFoundException ,其消息字符串设置为系统提供的消息,并将其 HRESULT 设置为COR_E_DIRECTORYNOTFOUND。

DirectoryNotFoundException(String)

初始化类的新实例 DirectoryNotFoundException ,并将其消息字符串设置为 message COR_E_DIRECTORYNOTFOUND。

DirectoryNotFoundException(SerializationInfo, StreamingContext)
已过时.

使用指定的序列化和上下文信息初始化 DirectoryNotFoundException 类的新实例。

DirectoryNotFoundException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用初始化 DirectoryNotFoundException 类的新实例。

DirectoryNotFoundException(String, String)
DirectoryNotFoundException(String, String, Exception)

DirectoryNotFoundException()

Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs

初始化类的新实例 DirectoryNotFoundException ,其消息字符串设置为系统提供的消息,并将其 HRESULT 设置为COR_E_DIRECTORYNOTFOUND。

public:
 DirectoryNotFoundException();
public DirectoryNotFoundException();
Public Sub New ()

示例

下面的代码示例演示如何调用 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);
        }
    }
}
Imports System.IO

Module Module1
    Sub Main()
        Try

            ' Specify a directory name that does not exist for this demo.
            Dim dir As String = "c:\78fe9lk"

            ' If this directory does not exist, a DirectoryNotFoundException is thrown
            ' when attempting to set the current directory.
            Directory.SetCurrentDirectory(dir)

        Catch ex As System.IO.DirectoryNotFoundException

            ' Let the user know that the directory did not exist.
            Console.WriteLine("Directory not found: " + ex.Message)
        End Try
    End Sub
End Module

注解

此构造函数将 Exception.Message 新实例的属性初始化为系统提供的消息,该消息描述错误,例如“找不到指定的目录”。此消息将考虑当前系统区域性。

Exception.InnerException 实例的属性初始化为 null.

另请参阅

适用于

DirectoryNotFoundException(String)

Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs

初始化类的新实例 DirectoryNotFoundException ,并将其消息字符串设置为 message COR_E_DIRECTORYNOTFOUND。

public:
 DirectoryNotFoundException(System::String ^ message);
public DirectoryNotFoundException(string message);
public DirectoryNotFoundException(string? message);
new System.IO.DirectoryNotFoundException : string -> System.IO.DirectoryNotFoundException
Public Sub New (message As String)

参数

message
String

描述错误的 A Stringmessage 的内容旨在由人类理解。 此构造函数的调用方必须确保此字符串已本地化为当前系统区域性。

注解

此构造函数使用 Exception.Message.. 初始化message新实例的属性。

Exception.InnerException 实例的属性初始化为 null.

另请参阅

适用于

DirectoryNotFoundException(SerializationInfo, StreamingContext)

Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs

注意

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

使用指定的序列化和上下文信息初始化 DirectoryNotFoundException 类的新实例。

protected:
 DirectoryNotFoundException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected DirectoryNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected DirectoryNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.IO.DirectoryNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.IO.DirectoryNotFoundException
new System.IO.DirectoryNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.IO.DirectoryNotFoundException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo

保存所引发异常的序列化对象数据的 SerializationInfo

context
StreamingContext

包含有关源或目标的上下文信息的 StreamingContext

属性

另请参阅

适用于

DirectoryNotFoundException(String, Exception)

Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs
Source:
DirectoryNotFoundException.cs

使用指定的错误消息和对作为此异常原因的内部异常的引用初始化 DirectoryNotFoundException 类的新实例。

public:
 DirectoryNotFoundException(System::String ^ message, Exception ^ innerException);
public DirectoryNotFoundException(string message, Exception innerException);
public DirectoryNotFoundException(string? message, Exception? innerException);
new System.IO.DirectoryNotFoundException : string * Exception -> System.IO.DirectoryNotFoundException
Public Sub New (message As String, innerException As Exception)

参数

message
String

解释异常原因的错误消息。

innerException
Exception

是当前异常原因的异常。 如果未 innerExceptionnull 参数,则会在处理内部异常的 catch 块中引发当前异常。

注解

作为上一个异常的直接结果引发的异常应包括对 InnerException 属性中上一个异常的引用。 InnerException 属性返回传入构造函数的相同值,或者如果 null 属性未向构造函数提供内部异常值,则返回 InnerException

下表显示了 DirectoryNotFoundException实例的初始属性值。

财产 价值
InnerException 内部异常引用。
Message 错误消息字符串。

另请参阅

适用于

DirectoryNotFoundException(String, String)

Source:
DirectoryNotFoundException.cs
public:
 DirectoryNotFoundException(System::String ^ message, System::String ^ directoryPath);
public DirectoryNotFoundException(string? message, string? directoryPath);
new System.IO.DirectoryNotFoundException : string * string -> System.IO.DirectoryNotFoundException
Public Sub New (message As String, directoryPath As String)

参数

message
String
directoryPath
String

适用于

DirectoryNotFoundException(String, String, Exception)

Source:
DirectoryNotFoundException.cs
public:
 DirectoryNotFoundException(System::String ^ message, System::String ^ directoryPath, Exception ^ innerException);
public DirectoryNotFoundException(string? message, string? directoryPath, Exception? innerException);
new System.IO.DirectoryNotFoundException : string * string * Exception -> System.IO.DirectoryNotFoundException
Public Sub New (message As String, directoryPath As String, innerException As Exception)

参数

message
String
directoryPath
String
innerException
Exception

适用于