Nếu một thư mục bạn đang cố gắng tìm không tồn tại, thì DirectoryNotFoundException sẽ xảy ra.
Ở đây, chúng tôi đang cố gắng tìm một thư mục không tồn tại bằng phương thức GetDirectories ().
Ví dụ
using System.IO;
using System;
class Program {
static void Main() {
Directory.GetDirectories("D:\\new\\");
}
} Đoạn mã trên sẽ tạo ra ngoại lệ sau vì thư mục “D:\\ new” không tồn tại.
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path