Example

using System;
using System.IO;

namespace Samples
{
  public class FileNotFoundExceptionSample
  {
    public static void Main()
    {
      try
      {
        string s = "NotExists.txt";
        using(FileStream fs = File.Open(s, FileMode.Open))
        {
          Console.WriteLine("File opened: {0}", s);
        }
      }
      catch(FileNotFoundException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Exception: System.IO.FileNotFoundException: Could not find file "C:\Books\BCL\ Samples\System.IO\FileNotFoundException\NotExists.txt". File name: "C:\Books\BCL\Samples\System.IO\FileNotFoundException\NotExists.txt" at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.