Using Java.net Socket

That won't catch everything. And it mixes data types for e. I use (and strongly recommend) this construct (shown as if a library script):

from java.lang import Throwable
logger = system.util.getLogger(system.util.getProjectName() + '.' + __name__)

def someTask():
	try:
		someaction()
	except Throwable, t:
		# Throwable is the ultimate superclass of all java exceptions and errors
		logger.warn("some text for java", t)
	except Exception, e
		# Exception is python's superclass (technically BaseException--substitute if you like)
		logger.warn("some text for jython", later.PythonAsJavaException(e))

Note that you cannot use jython exceptions with loggers, and you should always be using loggers (no prints). Which is why the separate except: clause is so important--you have extra work required to log a python exception. (PythonAsJavaException() is available in my later.py.)

If you have common handling needed for both exception cases, move that into another function.

2 Likes