DirectoryNotFoundException 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化該類別的新實例 DirectoryNotFoundException 及其訊息字串。
多載
| 名稱 | Description |
|---|---|
| DirectoryNotFoundException() |
初始化該類別的新實例 DirectoryNotFoundException ,其訊息字串設為系統提供的訊息,HRESULT 設為 COR_E_DIRECTORYNOTFOUND。 |
| DirectoryNotFoundException(String) |
初始化一個新的類別實例 DirectoryNotFoundException ,訊息字串設為 , |
| DirectoryNotFoundException(SerializationInfo, StreamingContext) |
已淘汰.
初始化類別的新實例 DirectoryNotFoundException ,並依指定的序列化與上下文資訊。 |
| DirectoryNotFoundException(String, Exception) |
初始化類別的新實例 DirectoryNotFoundException ,並附上指定的錯誤訊息及導致該異常的內部例外的參考。 |
DirectoryNotFoundException()
初始化該類別的新實例 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)
初始化一個新的類別實例 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化Exception.Message新實例的屬性。
Exception.InnerException新實例的屬性初始化為 null。
另請參閱
適用於
DirectoryNotFoundException(SerializationInfo, StreamingContext)
警告
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
the that StreamingContext 包含了關於來源或目的地的上下文資訊。
- 屬性
另請參閱
適用於
DirectoryNotFoundException(String, Exception)
初始化類別的新實例 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 | 錯誤訊息字串。 |