There is no equivalent.
You could put a try/catch around every statement, but that has 2
implications:
1) Your code will be littered with try/catch blocks and hard to read - not
to mention much longer
2) Catching/processing exceptions is a costly thing. If half your nodes are
missing, and you are throwin/catching dozens/hundreds of exceptions, your
code would run noticeably slower.
Your best bet is to code in such a way as to avoid exceptions being raised
in the first place. The way you would prefer to have is just lazy coding -
the most efficient way is to just avoid having these exceptions thrown in
the first place.
Test the result of SelectSingleNode to make sure it is not null, and only
then proceed with whatever else you were going to do.
"Dave" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
Hi,
I have a C# program that is parsing an XML file and
loading a database table. Some of the elements may be
missing but I want to continue with loading the data
anyway because they may not be applicable.
So, if '190' doesn't exist using the following code:
doc.SelectSingleNode("descendant::companyinfo
[@a:sourceid='190']/sourcekey/id", nsmgr).InnerText
will raise:
"Object reference not set to an instance of an object."
I just want to continue processing subsequent nodes. How
can I mimic the resume next in VB. Can you test for
certain exceptions and decide to continue.
Thanks Dave