DirectoryNotFoundException 建構函式

定義

使用其訊息字串,初始化 DirectoryNotFoundException 類別的新執行個體。

多載

DirectoryNotFoundException()

將其訊息字串設定為系統提供的訊息且將其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。

DirectoryNotFoundException(String)

使用其訊息字串設定為 message 和其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。

DirectoryNotFoundException(SerializationInfo, StreamingContext)
已淘汰.

使用指定的序列化及內容資訊,初始化 DirectoryNotFoundException 類別的新執行個體。

DirectoryNotFoundException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 DirectoryNotFoundException 類別的新執行個體。

DirectoryNotFoundException()

來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs

將其訊息字串設定為系統提供的訊息且將其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。

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)

來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs

使用其訊息字串設定為 message 和其 HRESULT 設定為 COR_E_DIRECTORYNOTFOUND,初始化 DirectoryNotFoundException 類別的新執行個體。

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)

來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs
來源:
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)

來源:
DirectoryNotFoundException.cs
來源:
DirectoryNotFoundException.cs
來源:
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 屬性傳回的值會與傳入建構函式的值相同,或傳回 null (如果 InnerException 屬性未提供內部例外狀況值給建構函式)。

下表顯示 DirectoryNotFoundException 執行個體的初始屬性值。

屬性
InnerException 內部例外狀況參考。
Message 錯誤訊息字串。

另請參閱

適用於