DirectoryNotFoundExceptionとは? わかりやすく解説

DirectoryNotFoundException クラス

ファイルまたはディレクトリの一部が見つからない場合にスローされる例外。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class DirectoryNotFoundException
    Inherits IOException
Dim instance As DirectoryNotFoundException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class DirectoryNotFoundException : IOException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class DirectoryNotFoundException
 : public IOException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class DirectoryNotFoundException extends
 IOException
SerializableAttribute 
ComVisibleAttribute(true) 
public class DirectoryNotFoundException extends
 IOException
解説解説

DirectoryNotFoundException は、値 0x80070003 の HRESULT COR_E_DIRECTORYNOTFOUND を使用します。DirectoryNotFoundException は、COM 相互運用プログラムが値 0x80030003 の HRESULT STG_E_PATHNOTFOUND を参照するときにもスローされるため注意してください。

使用例使用例

DirectoryNotFoundException の強制的な発生や、DirectoryNotFoundException からの回復を行う方法を次のコード例に示します。

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
継承階層継承階層
System.Object
   System.Exception
     System.SystemException
       System.IO.IOException
        System.IO.DirectoryNotFoundException
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DirectoryNotFoundException コンストラクタ ()

メッセージ文字列がシステムによって提供されたメッセージに設定され、HRESULT が COR_E_DIRECTORYNOTFOUND に設定された DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As New DirectoryNotFoundException
public DirectoryNotFoundException ()
public:
DirectoryNotFoundException ()
public DirectoryNotFoundException ()
public function DirectoryNotFoundException
 ()
解説解説
使用例使用例

DirectoryNotFoundException コンストラクタを呼び出す方法を次のコード例に示します。

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DirectoryNotFoundException コンストラクタ (String)

メッセージ文字列を message に設定し、HRESULT を COR_E_DIRECTORYNOTFOUND に設定して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim message As String

Dim instance As New DirectoryNotFoundException(message)
public DirectoryNotFoundException (
    string message
)
public:
DirectoryNotFoundException (
    String^ message
)
public DirectoryNotFoundException (
    String message
)
public function DirectoryNotFoundException
 (
    message : String
)

パラメータ

message

エラーを説明する String。message の内容は、ユーザーが理解できる内容にします。このコンストラクタの呼び出し元は、この文字列が現在のシステムのカルチャに合わせてローカライズ済みであることを確認しておく必要があります。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DirectoryNotFoundException コンストラクタ

メッセージ文字列を設定して、DirectoryNotFoundException クラスのインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
DirectoryNotFoundException () メッセージ文字列がシステムによって提供されたメッセージに設定され、HRESULT が COR_E_DIRECTORYNOTFOUND に設定された DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

DirectoryNotFoundException (String) メッセージ文字列を message に設定し、HRESULT を COR_E_DIRECTORYNOTFOUND に設定して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

DirectoryNotFoundException (SerializationInfo, StreamingContext) 指定したシリアル化情報とコンテキスト情報を使用して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。
DirectoryNotFoundException (String, Exception) 指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。
参照参照

関連項目

DirectoryNotFoundException クラス
DirectoryNotFoundException メンバ
System.IO 名前空間

その他の技術情報

ファイルおよびストリーム入出力
方法 : ファイルからテキストを読み取る
方法 : ファイルにテキストを書き込む

DirectoryNotFoundException コンストラクタ (String, Exception)

指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New DirectoryNotFoundException(message,
 innerException)
public DirectoryNotFoundException (
    string message,
    Exception innerException
)
public:
DirectoryNotFoundException (
    String^ message, 
    Exception^ innerException
)
public DirectoryNotFoundException (
    String message, 
    Exception innerException
)
public function DirectoryNotFoundException
 (
    message : String, 
    innerException : Exception
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

innerException

現在の例外の原因である例外。innerException パラメータが null 参照 (Visual Basic では Nothing) でない場合は、内部例外を処理する catch ブロックで現在の例外が発生します。

解説解説

前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照が格納されます。InnerException プロパティは、コンストラクタに渡されたものと同じ値を返します。InnerException プロパティによって内部例外値がコンストラクタに渡されなかった場合は、null 参照 (Visual Basic では Nothing) を返します。

DirectoryNotFoundException のインスタンスの初期プロパティ値を次の表に示します。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DirectoryNotFoundException コンストラクタ (SerializationInfo, StreamingContext)

指定したシリアル化情報とコンテキスト情報を使用して、DirectoryNotFoundException クラスの新しいインスタンスを初期化します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New DirectoryNotFoundException(info,
 context)
protected DirectoryNotFoundException (
    SerializationInfo info,
    StreamingContext context
)
protected:
DirectoryNotFoundException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected DirectoryNotFoundException (
    SerializationInfo info, 
    StreamingContext context
)
protected function DirectoryNotFoundException
 (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

スローされている例外に関するシリアル化済みオブジェクト データを保持している SerializationInfo。

context

転送元または転送先に関するコンテキスト情報を含んでいる StreamingContext。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DirectoryNotFoundException プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。 ( Exception から継承されます。)
参照参照

DirectoryNotFoundException メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

DirectoryNotFoundException メンバ

ファイルまたはディレクトリの一部が見つからない場合にスローされる例外。

DirectoryNotFoundException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド DirectoryNotFoundException オーバーロードされます。 メッセージ文字列を設定して、DirectoryNotFoundException クラスのインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DirectoryNotFoundException」の関連用語

DirectoryNotFoundExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DirectoryNotFoundExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS