# How catch NilObjectExeption in XML

**URL:** <https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574>\
**Category:** General\
**Created:** [November 20, 2016, 11:59pm UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574 "2016-11-20T23:59:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Despres](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@Denis\_Despres](https://forum.xojo.com/u/Denis_Despres)\
**Post date:** [November 20, 2016, 11:59pm UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/1 "2016-11-20T23:59:59Z")

</div>

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  
thanks

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [November 21, 2016, 12:19am UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/2 "2016-11-21T00:19:03Z")

</div>

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.  
oMyObject.DoSomething  
next  
[/code]

---

<div class="post-metadata">

**Author:** ![Denis\_Despres](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/65b543/32.png) [@Denis\_Despres](https://forum.xojo.com/u/Denis_Despres)\
**Post date:** [November 21, 2016, 12:26am UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/3 "2016-11-21T00:26:04Z")

</div>

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 )

---

<div class="post-metadata">

**Author:** ![Wayne\_Golding](https://forum.xojo.com/user_avatar/forum.xojo.com/wayne_golding/32/165_2.png) [@Wayne\_Golding](https://forum.xojo.com/u/Wayne_Golding)\
**Post date:** [November 21, 2016, 2:26am UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/4 "2016-11-21T02:26:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [November 21, 2016, 6:54am UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/5 "2016-11-21T06:54:29Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:33pm UTC](https://forum.xojo.com/t/how-catch-nilobjectexeption-in-xml/34574/6 "2020-10-29T18:33:35Z")

</div>


