user1725266
user1725266

Reputation: 466

DirectoryNotFoundException was unhandled by user code

I'm quite new to the try catch and exception handling. I want my program to catch the exception when the directory or file is not found. Whenever I run the program I get the error "DirectoryNotFoundException was unhandled by user code - An exception of type 'System.IO.DirectoryNotFoundException' occured in something.dll but was not handled in user code"

I can see that Visual Studio breaks at the DirectoryNotFoundDirection, any ideas?

try {
    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(filePath);
    var result = await operation.StartAsync();
}
catch (FileNotFoundException filEx) {
   Debug.WriteLine(filEx.Message);
   throw filEx;
}
catch (DirectoryNotFoundException dirEx) {
   Debug.WriteLine(dirEx.Message);
   throw;
}
catch (IOException ioEx) {
    Debug.WriteLine(ioEx.Message);
    throw ioEx;
}
catch (Exception ex) {
    Debug.WriteLine(ex.Message);
    throw;
}

EDIT: to show code inside try

Upvotes: 0

Views: 1630

Answers (1)

Gary Walker
Gary Walker

Reputation: 9134

Because the directory does not exist (or has permissions problems, etc.), it throws an DirectoryNotFoundException.

Which you handle, then reraise -- because of the, the debugger rightly says that the exception is not handled.

Upvotes: 2

Related Questions