System.IO.DirectoryNotFoundException Class

public class DirectoryNotFoundException : IOException

Base Types

Object
  Exception
    SystemException
      IOException
        DirectoryNotFoundException

Assembly

mscorlib

Library

BCL

Summary

Represents the error that occurs when part of a file or directory argument cannot be found.

Example

The following example demonstrates an error that causes the DirectoryNotFoundException exception to be thrown. In this case, the /Mistake/examples/ directory does not exist and therefore cannot be located.

using System;
using System.IO;
class DirectoryNotFoundExample {
 public static void Main () {
 string badPath = "/Mistake/examples/";
 try {
 Directory.GetFiles(badPath);
 }
 catch (DirectoryNotFoundException e) {
 Console.WriteLine("Caught: {0}",e.Message);
 }
 }
}
The output is

Caught: Could not find a part of the path "C:\Mistake\examples".

See Also

System.IO Namespace

Members

DirectoryNotFoundException Constructors

DirectoryNotFoundException() Constructor
DirectoryNotFoundException(System.String) Constructor
DirectoryNotFoundException(System.String, System.Exception) Constructor


DirectoryNotFoundException() Constructor

public DirectoryNotFoundException();

Summary

Constructs and initializes a new instance of the DirectoryNotFoundException class.

Description

This constructor initializes the System.IO.DirectoryNotFoundException.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.

The System.IO.DirectoryNotFoundException.InnerException property of the new instance is initialized to null .

See Also

System.IO.DirectoryNotFoundException Class, System.IO Namespace

DirectoryNotFoundException(System.String) Constructor

public DirectoryNotFoundException(string message);

Summary

Constructs and initializes a new instance of the DirectoryNotFoundException class.

Parameters

message
A String that describes the error. 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.

Description

This constructor initializes the System.IO.DirectoryNotFoundException.Message property of the new instance using message. If message is null , the System.IO.DirectoryNotFoundException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.IO.DirectoryNotFoundException.InnerException property is initialized to null .

See Also

System.IO.DirectoryNotFoundException Class, System.IO Namespace

DirectoryNotFoundException(System.String, System.Exception) Constructor

public DirectoryNotFoundException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the DirectoryNotFoundException class.

Parameters

message
A String that describes the error. 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.
innerException
An instance of Exception that is the cause of the current exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException.

Description

This constructor initializes the System.IO.DirectoryNotFoundException.Message property of the new instance using message and the System.IO.DirectoryNotFoundException.InnerException property using innerException. If message is null , the System.IO.DirectoryNotFoundException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

[Note: For more information on inner exceptions, see System.Exception.InnerException.]

See Also

System.IO.DirectoryNotFoundException Class, System.IO Namespace