# system.util.jsonDecode error not caught by try/except in gateway script

**URL:** <https://forum.inductiveautomation.com/t/system-util-jsondecode-error-not-caught-by-try-except-in-gateway-script/35474>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [June 9, 2020, 9:54pm UTC](https://forum.inductiveautomation.com/t/system-util-jsondecode-error-not-caught-by-try-except-in-gateway-script/35474 "2020-06-09T21:54:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimschaefer](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jimschaefer](https://forum.inductiveautomation.com/u/jimschaefer)\
**Post date:** [June 9, 2020, 9:54pm UTC](https://forum.inductiveautomation.com/t/system-util-jsondecode-error-not-caught-by-try-except-in-gateway-script/35474/1 "2020-06-09T21:54:46Z")

</div>

When I get an error in the system.util.jsonDecode function running in a global script the error appears in the diagnostic log on the web interface ([http://localhost:8088/main/web/status/diag.logviewer?5](http://localhost:8088/main/web/status/diag.logviewer?5)) and the script aborts. I would expect the except portion of the code to run and the script to continue. I am calling my script every two seconds in a Gateway event script

```auto
badJSONstringExample = "{"
try:
   steeringPlanDict = system.util.jsonDecode(badJSONstringExample )
except Exception, e:
   #never gets here
   isValid = False
   eventMessage = "Failed to decode JSON string"
   logError (eventMessage)

```

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 9, 2020, 9:59pm UTC](https://forum.inductiveautomation.com/t/system-util-jsondecode-error-not-caught-by-try-except-in-gateway-script/35474/2 "2020-06-09T21:59:16Z")

</div>

It’s probably a Java exception and you’re trapping Python exceptions with your except statement. Unfortunately they don’t inherit from the same class.

Try adding  
`except java.lang.Exception as e:`

---

<div class="post-metadata">

**Author:** ![jimschaefer](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jimschaefer](https://forum.inductiveautomation.com/u/jimschaefer)\
**Post date:** [June 9, 2020, 10:03pm UTC](https://forum.inductiveautomation.com/t/system-util-jsondecode-error-not-caught-by-try-except-in-gateway-script/35474/3 "2020-06-09T22:03:24Z")

</div>

Great tip ! Thanks

Here is the working code… note slightly different except syntax:

```auto
badJSONstringExample = "{"
try:
   steeringPlanDict = system.util.jsonDecode(badJSONstringExample )

#except Exception, e: #this doesn't work
except java.lang.Exception , e: #this does
   #now it gets here
   isValid = False
   eventMessage = "Failed to decode JSON string: " + e.toString()
   logError (eventMessage)

```
