DirectoryNotFoundException 构造函数

定义

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

重载

DirectoryNotFoundException()

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

DirectoryNotFoundException(String)

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

DirectoryNotFoundException(SerializationInfo, StreamingContext)
已过时.

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

DirectoryNotFoundException(String, Exception)

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

DirectoryNotFoundException()

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

初始化 DirectoryNotFoundException 类的新实例,使其消息字符串设置为 message,其 HRESULT 设置为 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

描述该错误的 Stringmessage 的内容设计为易于理解。 此构造函数的调用方需要确保此字符串已针对当前系统区域性进行了本地化。

注解

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

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

另请参阅

适用于

DirectoryNotFoundException(SerializationInfo, StreamingContext)

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);
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);
new System.IO.DirectoryNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.IO.DirectoryNotFoundException
[<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
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

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 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

导致当前异常的异常。 如果 innerException 参数不为 null,则当前异常将在处理内部异常的 catch 块中引发。

注解

因前一个异常而直接引发的异常应在 InnerException 属性中包含对前一个异常的引用。 InnerException 属性将返回传递给构造函数的同一值;如果 InnerException 属性不向构造函数提供内部异常值,则返回 null

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

properties “值”
InnerException 内部异常引用。
Message 错误消息字符串。

另请参阅

适用于