How catch NilObjectExeption in XML

Hi everyone
I don’t understand how catch NilObjectExeption when searching through a xml value
I know that the value doesnt exist at every line, i must catch the nilExeption and set the value to “-” in the array that i construct from xml
I can’t loop throught the node itself because i need the index of the parent to match the array position

For i As Integer = 0 To nodes.Length-1 node = nodes.Item(i) if node.FirstChild=Nil Then myArray.Append("-") Next
I know that code is wrong
like i said i didn’t understood the NilObjectExeption exemple in the doc

Well, not sure what your specific code is, but the phrase Continue will skip the rest of the loop so you can use that in combination with nil checking to skip items that don’t exist.

This code offering by no means improves your code, and chances are this is not the best way to do it with XML reading.

[code]for i as Integer = 0 to aroObject.Ubound
dim oMyObject as Object = aroObject(i)

if oMyObject = nil then continue
// if oMyObject is nil the rest of the loop is skipped for this iteration.

// You can be sure here that oMyObject is not nil.

thanks Tim
But i realize that is not only the catch NilObject that i dont understand
My original code didn’t work at the runtime but Work well when its built
is it normal
It work because i’v put the catch after my loop

Exception err as NilObjectException MsgBox "No data"
But only in built app

Like i said i dont understand the catch function because i cant include it inside my loop ( variable )

You will need to use #pragma BreakOnExceptions Off to get the debugger to ignore the error and let your app handle it.

[quote=299334:@Denis Despres]My original code didn’t work at the runtime but Work well when its built
is it normal[/quote]
Yes. By default the IDE always pauses on an exception. You can press Resume to continue your code, which will jump to the Exception handler at the end. You can turn that off in the IDE or with the Pragma that Wayne mentioned.