It is because you have not written
xDoc.Load(File.FullName);
inside the try block. That is the reason why the exception was not handled.
It is because you have not written
xDoc.Load(File.FullName);
inside the try block. That is the reason why the exception was not handled.
The other answer about putting Load() inside the try block is right, but doesn't actually explain why SelectNodes() "appears" to be throwing an XmlException that is not being caught.
The actual answer is that the debugger is confused/out of sync with your source code and is actually showing the wrong line as causing the exception.
It should really be pointing to the xDoc.Load(File.FullName); , in which case it would be clear that this call should be inside the try block.
Why? Notice the XmlLoader.LoadNode() in the last line of the stack trace. In .NET Reflector you can see that the XmlDocument.Load() method (deep in it's bowels) calls the LoadNode() method.
However, also in reflector, it can be seen that the SelectNodes() method does not call LoadNode() anywhere in it's internal implementation.
So according to the stack trace, the exception cannot have been caused by SelectNodes().
I've seen the debugger get confused like this before when a code change is made and debugging started, but the debugging symbols have not been updated correctly. Try cleaning and re-building your solution to refresh the debugging symbols.