DirectoryNotFoundException 建構函式

定義

使用其訊息字串,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with its message string.

多載

DirectoryNotFoundException()

將其訊息字串設定為系統提供的訊息且將其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with its message string set to a system-supplied message and its HRESULT set to COR_E_DIRECTORYNOTFOUND.

DirectoryNotFoundException(String)

使用其訊息字串設定為 message 和其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with its message string set to message and its HRESULT set to COR_E_DIRECTORYNOTFOUND.

DirectoryNotFoundException(SerializationInfo, StreamingContext)

使用指定的序列化 (Serialization) 和內容資訊,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with the specified serialization and context information.

DirectoryNotFoundException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

DirectoryNotFoundException()

將其訊息字串設定為系統提供的訊息且將其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with its message string set to a system-supplied message and its HRESULT set to COR_E_DIRECTORYNOTFOUND.

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

範例

下列程式碼範例示範如何呼叫此DirectoryNotFoundException函式。The following code example demonstrates how to call the DirectoryNotFoundException constructor.

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將新實例的屬性初始化為系統提供的訊息, 以描述錯誤, 例如「找不到指定的目錄」。This constructor initializes the Exception.Message property of the new instance to a system-supplied message that describes the error, such as "Could not find the specified directory." 此訊息會考量目前的系統文化特性。This message takes into account the current system culture.

Exception.InnerException實例的屬性會初始化為。 nullThe Exception.InnerException property of the new instance is initialized to null.

另請參閱

DirectoryNotFoundException(String)

使用其訊息字串設定為 message 和其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with its message string set to message and its HRESULT set to COR_E_DIRECTORYNOTFOUND.

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

參數

message
String

描述錯誤的 StringA String that describes the error. message 的內容必須能讓人了解。The content of message is intended to be understood by humans. 這個建構函式的呼叫端必須確保這個字串已經被當地語系化 (為了目前系統的文化特性)。The caller of this constructor is required to ensure that this string has been localized for the current system culture.

備註

這個函式會Exception.Message使用message初始化新實例的屬性。This constructor initializes the Exception.Message property of the new instance using message.

Exception.InnerException實例的屬性會初始化為。 nullThe Exception.InnerException property of the new instance is initialized to null.

另請參閱

DirectoryNotFoundException(SerializationInfo, StreamingContext)

使用指定的序列化 (Serialization) 和內容資訊,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with the specified serialization and context information.

protected:
 DirectoryNotFoundException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
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
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

SerializationInfo,包含所擲回之例外狀況的相關序列化物件資料。The SerializationInfo that holds the serialized object data about the exception being thrown.

context
StreamingContext

包含有關來源或目的端內容資訊的 StreamingContextThe StreamingContext that contains contextual information about the source or destination.

另請參閱

DirectoryNotFoundException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 DirectoryNotFoundException 類別的新執行個體。Initializes a new instance of the DirectoryNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

public:
 DirectoryNotFoundException(System::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

解釋例外狀況原因的錯誤訊息。The error message that explains the reason for the exception.

innerException
Exception

做為目前例外狀況發生原因的例外狀況。The exception that is the cause of the current exception. 如果 innerException 參數不是 null,則目前的例外狀況會在處理內部例外的 catch 區塊中引發。If the innerException parameter is not null, the current exception is raised in a catch block that handles the inner exception.

備註

被擲回以做為前一個例外狀況直接結果的例外狀況,應該在 InnerException 屬性中包含對前一個例外狀況的參考。An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the InnerException property. InnerException 屬性會傳回與傳入建構函式中相同的值;如果 null 屬性沒有提供內部例外值給建構函式,則傳回 InnerExceptionThe InnerException property returns the same value that is passed into the constructor, or null if the InnerException property does not supply the inner exception value to the constructor.

下表顯示 DirectoryNotFoundException 執行個體的初始屬性值。The following table shows the initial property values for an instance of DirectoryNotFoundException.

屬性Property Value
InnerException 內部例外狀況參考。The inner exception reference.
Message 錯誤訊息字串。The error message string.

另請參閱

適用於