Multiple try/except blocks

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?

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)

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.

1 Like

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

1 Like

Yeah, that’s what you need.

2 Likes

Ok, thanks, guys.