Example

using System;
using System.IO;
namespace Samples
{
  public class DirectoryNotFoundExceptionSample
  {
    public static void Main()
    {
      try
      {
        string n = @"C:\foo\bar";
        string[] s = Directory.GetFiles(n);
      }
      catch(DirectoryNotFoundException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path "C:\foo\bar". at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.Directory.InternalGetFileDirectoryNames(String fullPath, Boolean file) at System.IO.Directory.InternalGetFiles(String path, String searchPattern) at System.IO.Directory.GetFiles(String path, String searchPattern) at System.IO.Directory.GetFiles(String path) at Samples.DirectoryNotFoundExceptionSample.Main() ...

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.