# Try Catch not working

**URL:** <https://forum.xojo.com/t/try-catch-not-working/43299>\
**Category:** Web\
**Created:** [May 3, 2018, 5:57am UTC](https://forum.xojo.com/t/try-catch-not-working/43299 "2018-05-03T05:57:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Baughman](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@John\_Baughman](https://forum.xojo.com/u/John_Baughman)\
**Post date:** [May 3, 2018, 5:57am UTC](https://forum.xojo.com/t/try-catch-not-working/43299/1 "2018-05-03T05:57:25Z")

</div>

I am tring to catch a NilObjectException in the follwoing code…

[code] Try  
location.Address = lbContacts.Cell(lbContacts.ListIndex,1)  
WebPage1.MapViewer1.GoToLocation(location)  
tfLocation.text=lbContacts.Cell(lbContacts.ListIndex,1)

Catch e As NilObjectException  
MsgBox “Not Found. The entered address is probably not valid.”

End Try[/code]

I also tried Catch e As RuntimeException. Neither catch the errror. The app stops with a NilObjectException error on “Location.Address =…” where the error is expected.

What am I doing wrong, or am I not understanding how this works?

Thanks,

John

---

<div class="post-metadata">

**Author:** ![John\_Baughman](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@John\_Baughman](https://forum.xojo.com/u/John_Baughman)\
**Post date:** [May 3, 2018, 6:13am UTC](https://forum.xojo.com/t/try-catch-not-working/43299/2 "2018-05-03T06:13:14Z")

</div>

OK. I got it. The exception is ignored only if the application is not in debug mode, and in debug mode it continues to the catch code and the app continues to run.

John

---

<div class="post-metadata">

**Author:** ![Massimo\_Valle](https://forum.xojo.com/user_avatar/forum.xojo.com/massimo_valle/32/23049_2.png) [@Massimo\_Valle](https://forum.xojo.com/u/Massimo_Valle)\
**Post date:** [May 3, 2018, 6:36am UTC](https://forum.xojo.com/t/try-catch-not-working/43299/3 "2018-05-03T06:36:28Z")

</div>

You can toggle Break On Exceptions in Project menu to prevent breaking in debug.  
You can even use `#pragma BreakOnExceptions false` in the method and the setting will only last for that method.

---

<div class="post-metadata">

**Author:** ![John\_Baughman](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@John\_Baughman](https://forum.xojo.com/u/John_Baughman)\
**Post date:** [May 3, 2018, 11:31pm UTC](https://forum.xojo.com/t/try-catch-not-working/43299/4 "2018-05-03T23:31:30Z")

</div>

@Massimo Valle Thanks. Learned something new again!

---

<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, 7:12pm UTC](https://forum.xojo.com/t/try-catch-not-working/43299/5 "2020-10-29T19:12:08Z")

</div>


