Let's say I create and execute a System.Net.FtpWebRequest.
I can use catch (WebException ex) {} to catch any web related exception thrown by this request, but what if I have some logic that I only want to execute when the exception is thrown due to (550) file not found
.
What's the best way to do this?
I can copy the exception message and test for equality:
const string fileNotFoundExceptionMessage = "The remote server returned an error: (550) File unavailable (e.g., file not found, no access).";
if (ex.Message == fileNotFoundExceptionMessage) {
but theoretically it seems like this message could change down the road.
I can just test to see if the exception message contains "550", which is probably more likely to work if the message is changed (it will likely still contain 550 somewhere in the text) but of course will also return true if the text for some other WebException just happens to contain 550.
There doesn't seem to be a method for accessing just the number of the exception.
Any thoughts?