# Multiple try/except blocks

**URL:** <https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 3, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652 "2022-08-03T19:57:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 3, 2022, 7:57pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652/1 "2022-08-03T19:57:57Z")

</div>

I need a sanity check.

If I have a set of functions that I want to run from a tag change event, regardless of whether there is an exception in each preceding block, is this syntax what I’m needing? Or am I missing something more elegant?

```python
from java.lang import Throwable
import traceback

logger = system.util.getLogger('myExceptionLogger')

try:
	runCodeA()
except Throwable, t:
	logger.warn("CodeA failed with a Java exception: ", t)
except Exception, e:
	logger.warn("CodeA failed with a Jython exception: ", e)
	
try:
	runCodeB()
except Throwable, t:
	logger.warn("CodeB failed with a Java exception: ", t)
except Exception, e:
	logger.warn("CodeB failed with a Jython exception: ", e)

try:
	runCodeC()
except Throwable, t:
	logger.warn("CodeC failed with a Java exception: ", t)
except Exception, e:
	logger.warn("CodeC failed with a Jython exception: ", e)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 3, 2022, 8:03pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652/2 "2022-08-03T20:03:32Z")

</div>

Aside from doing something fancy (like a decorator) to get the proper function name and only using a single try/except which might not even be applicable to your situation. This would be what I used.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 3, 2022, 8:04pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652/3 "2022-08-03T20:04:49Z")

</div>

Yeah, I was wanting runCodeB() to execute, regardless of what happens to runCodeA, etc.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 3, 2022, 8:06pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652/4 "2022-08-03T20:06:28Z")

</div>

Yeah, that’s what you need.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 3, 2022, 8:08pm UTC](https://forum.inductiveautomation.com/t/multiple-try-except-blocks/62652/5 "2022-08-03T20:08:09Z")

</div>

Ok, thanks, guys.
