How to check if path is valid without using try-catch?
问题 I want to check if a folder exists and if not then create it. But I don't know if the path supplied will even valid. When the path is not valid the following happens. string path = "this is an invalid path"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); //Exception thrown here If you supply an invalid path, it will throw a DirectoryNotFoundException exception. How can I stop this exception from occurring? I don't want to use a try-catch. I want to detect that this exception