Parsing XML exception

I am trying to parse an XML tag, provided as a string, to ensure it is well formed XML. I tried to use the XMLDocument.LoadXML method and if the string is well formed, all is OK. However, when the string is not well formed I get an XMLException.

I have encapsulated the LoadXML call inside a Try…Catch… End Try block but the Catch err as XMLException does not intercept the XMLException. I have also tried exchanging the Catch statement with an Exception statement, which according to the manual should be a blanket interception and XMLDomException. However, this does not intercept the exception either.

Can anyone provide me with some advice of where I am going wrong. Is there a better way of validating well formedness of an XML statement.


In debug mode you need to add a pragma before the try/catch block

#pragma BreakOnExceptions Off

[code] Dim x As New XmlDocument

#pragma BreakOnExceptions Off
x.LoadXml(“This is crap”)
Catch XmlException
MsgBox “That was crap”
End Try

Works for me.