0

I have a try catch that should catch an exception if the string has invalid characters for a Windows path.

 try { Result = Path.GetFullPath(pathname); } catch (System.IO.IOException e) { CatchResult = (e); } 

But an exception is still being thrown, and the application crash's. Any ideas?

1
  • 2
    What is the exception which is being thrown? Commented May 20, 2014 at 22:48

2 Answers 2

2

The MSDN states that the Path.GetFullPath() throws 5 kinds of exceptions but not IOException. You must catch the correct type of exception. See documentation for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

PathTooLongException is derived from IOException, so his catch would get that one.
2

Path.GetFullPath(string) does not throw IOException as one of it's available exceptions.

Please review the Exception list at Path.GetFullPath MSDN

Exceptions thrown:

  1. ArgumentException
  2. SecurityException
  3. ArgumentNullException
  4. NotSupportedException
  5. PathTooLongException.

1 Comment

To be fair, PathTooLongException is a descendant of IOException, so the catch would get that one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.