FileNotFoundException Class

The exception that is thrown when an attempt to access a file that does not exist on disk fails.

Syntax

Declaration

[Serializable]
[ComVisible(true)]
public class FileNotFoundException : IOException, ISerializable, _Exception

Inheritance Hierarchy

Constructors summary

Initializes a new instance of the FileNotFoundException class with its message string set to a system-supplied message and its HRESULT set to COR_E_FILENOTFOUND.

Initializes a new instance of the FileNotFoundException class with its message string set to message and its HRESULT set to COR_E_FILENOTFOUND.

Initializes a new instance of the FileNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Initializes a new instance of the FileNotFoundException class with its message string set to message, specifying the file name that cannot be found, and its HRESULT set to COR_E_FILENOTFOUND.

Initializes a new instance of the FileNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Properties summary

Gets the name of the file that cannot be found.

Gets the error message that explains the reason for the exception.

Methods summary

Returns the fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.

Constructors

  • FileNotFoundException()

    Initializes a new instance of the FileNotFoundException class with its message string set to a system-supplied message and its HRESULT set to COR_E_FILENOTFOUND.

    public FileNotFoundException()
  • FileNotFoundException(String)

    Initializes a new instance of the FileNotFoundException class with its message string set to message and its HRESULT set to COR_E_FILENOTFOUND.

    public FileNotFoundException(string message)

    Parameters

    • message

      A description of 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.

  • FileNotFoundException(String, Exception)

    Initializes a new instance of the FileNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

    public FileNotFoundException(string message, Exception innerException)

    Parameters

    • message

      A description of 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

      The exception that is the cause of the current exception. If the innerException parameter is not null, the current exception is raised in a catch block that handles the inner exception.

  • FileNotFoundException(String, String)

    Initializes a new instance of the FileNotFoundException class with its message string set to message, specifying the file name that cannot be found, and its HRESULT set to COR_E_FILENOTFOUND.

    public FileNotFoundException(string message, string fileName)

    Parameters

    • message

      A description of 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.

    • fileName

      The full name of the file with the invalid image.

  • FileNotFoundException(String, String, Exception)

    Initializes a new instance of the FileNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

    public FileNotFoundException(string message, string fileName, Exception innerException)

    Parameters

    • message

      The error message that explains the reason for the exception.

    • fileName

      The full name of the file with the invalid image.

    • innerException

      The exception that is the cause of the current exception. If the innerException parameter is not null, the current exception is raised in a catch block that handles the inner exception.

Properties

  • FileName

    Gets the name of the file that cannot be found.

    public string FileName { get; }

    Property Value

    • The name of the file, or null if no file name was passed to the constructor for this instance.

  • Message

    Gets the error message that explains the reason for the exception.

    public override string Message { get; }

    Property Value

    Overrides

Methods

  • ToString()

    Returns the fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.

    public override string ToString()

    Returns

    • The fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.

    Overrides

Details

Namespace

System.IO

Assembly

System.Runtime.dll

See Also